diff --git a/docs/build/doctrees/environment.pickle b/docs/build/doctrees/environment.pickle index f613efa..b576c40 100644 Binary files a/docs/build/doctrees/environment.pickle and b/docs/build/doctrees/environment.pickle differ diff --git a/docs/build/doctrees/pyFTS.models.doctree b/docs/build/doctrees/pyFTS.models.doctree index 7eb4aaa..e4f50b6 100644 Binary files a/docs/build/doctrees/pyFTS.models.doctree and b/docs/build/doctrees/pyFTS.models.doctree differ diff --git a/docs/build/doctrees/pyFTS.models.ensemble.doctree b/docs/build/doctrees/pyFTS.models.ensemble.doctree index ed22af5..608253f 100644 Binary files a/docs/build/doctrees/pyFTS.models.ensemble.doctree and b/docs/build/doctrees/pyFTS.models.ensemble.doctree differ diff --git a/docs/build/doctrees/pyFTS.models.incremental.doctree b/docs/build/doctrees/pyFTS.models.incremental.doctree new file mode 100644 index 0000000..f5a763f Binary files /dev/null and b/docs/build/doctrees/pyFTS.models.incremental.doctree differ diff --git a/docs/build/doctrees/pyFTS.probabilistic.doctree b/docs/build/doctrees/pyFTS.probabilistic.doctree index a264c17..34e5877 100644 Binary files a/docs/build/doctrees/pyFTS.probabilistic.doctree and b/docs/build/doctrees/pyFTS.probabilistic.doctree differ diff --git a/docs/build/html/_modules/index.html b/docs/build/html/_modules/index.html index cd64cda..85d0000 100644 --- a/docs/build/html/_modules/index.html +++ b/docs/build/html/_modules/index.html @@ -117,6 +117,7 @@
  • pyFTS.models.hofts
  • pyFTS.models.hwang
  • pyFTS.models.ifts
  • +
  • pyFTS.models.incremental.Retrainer
  • pyFTS.models.ismailefendi
  • pyFTS.models.multivariate.FLR
  • pyFTS.models.multivariate.common
  • diff --git a/docs/build/html/_modules/pyFTS/models/ensemble/ensemble.html b/docs/build/html/_modules/pyFTS/models/ensemble/ensemble.html index 94305c6..7e3e90a 100644 --- a/docs/build/html/_modules/pyFTS/models/ensemble/ensemble.html +++ b/docs/build/html/_modules/pyFTS/models/ensemble/ensemble.html @@ -72,8 +72,14 @@

    Source code for pyFTS.models.ensemble.ensemble

    -#!/usr/bin/python
    -# -*- coding: utf8 -*-
    +"""
    +EnsembleFTS wraps several FTS methods to ensemble their forecasts, providing point,
    +interval and probabilistic forecasting.
    +
    +Silva, P. C. L et al. Probabilistic Forecasting with Seasonal Ensemble Fuzzy Time-Series
    +XIII Brazilian Congress on Computational Intelligence, 2017. Rio de Janeiro, Brazil.
    +"""
    +
     
     import numpy as np
     import pandas as pd
    @@ -96,7 +102,7 @@
         """
         def __init__(self, **kwargs):
             super(EnsembleFTS, self).__init__(**kwargs)
    -        self.shortname = "Ensemble FTS"
    +        self.shortname = "EnsembleFTS"
             self.name = "Ensemble FTS"
             self.flrgs = {}
             self.has_point_forecasting = True
    @@ -108,13 +114,16 @@
             self.parameters = []
             """A list with the parameters for each component model"""
             self.alpha = kwargs.get("alpha", 0.05)
    +        """The quantiles """
             self.point_method = kwargs.get('point_method', 'mean')
    +        """The method used to mix the several model's forecasts into a unique point forecast. Options: mean, median, quantile"""
             self.interval_method = kwargs.get('interval_method', 'quantile')
    +        """The method used to mix the several model's forecasts into a interval forecast. Options: quantile, extremum, normal"""
             self.order = 1
     
     
    [docs] def append_model(self, model): """ - Append a new model to the ensemble + Append a new trained model to the ensemble :param model: FTS model @@ -341,6 +350,9 @@
    [docs]class AllMethodEnsembleFTS(EnsembleFTS): + """ + Creates an EnsembleFTS with all point forecast methods, sharing the same partitioner + """ def __init__(self, **kwargs): super(AllMethodEnsembleFTS, self).__init__(**kwargs) self.min_order = 3 diff --git a/docs/build/html/_modules/pyFTS/models/ensemble/multiseasonal.html b/docs/build/html/_modules/pyFTS/models/ensemble/multiseasonal.html index e04fd2f..3cd0f9b 100644 --- a/docs/build/html/_modules/pyFTS/models/ensemble/multiseasonal.html +++ b/docs/build/html/_modules/pyFTS/models/ensemble/multiseasonal.html @@ -72,8 +72,10 @@

    Source code for pyFTS.models.ensemble.multiseasonal

    -#!/usr/bin/python
    -# -*- coding: utf8 -*-
    +"""
    +Silva, P. C. L et al. Probabilistic Forecasting with Seasonal Ensemble Fuzzy Time-Series
    +XIII Brazilian Congress on Computational Intelligence, 2017. Rio de Janeiro, Brazil.
    +"""
     
     import numpy as np
     from pyFTS.common import Util as cUtil
    diff --git a/docs/build/html/_modules/pyFTS/models/incremental/Retrainer.html b/docs/build/html/_modules/pyFTS/models/incremental/Retrainer.html
    new file mode 100644
    index 0000000..79f0713
    --- /dev/null
    +++ b/docs/build/html/_modules/pyFTS/models/incremental/Retrainer.html
    @@ -0,0 +1,173 @@
    +
    +
    +
    +
    +
    +  
    +    
    +    
    +    pyFTS.models.incremental.Retrainer — pyFTS 1.2.3 documentation
    +    
    +    
    +    
    +    
    +    
    +    
    +    
    +    
    +    
    +    
    +    
    +    
    +  
    +    
    +      
    +
    +    
    +
    +
    +
    + +

    Source code for pyFTS.models.incremental.Retrainer

    +"""
    +Meta model that wraps another FTS method and continously retrain it using a data window with the most recent data
    +"""
    +
    +import numpy as np
    +from pyFTS.common import FuzzySet, FLR, fts, flrg
    +from pyFTS.partitioners import Grid
    +
    +
    +
    [docs]class Retrainer(fts.FTS): + """ + Meta model for incremental/online learning + """ + def __init__(self, **kwargs): + super(Retrainer, self).__init__(**kwargs) + + self.partitioner_method = kwargs.get('partitioner_method', Grid.GridPartitioner) + """The partitioner method to be called when a new model is build""" + self.partitioner_params = kwargs.get('partitioner_params', {'npart': 10}) + """The partitioner method parameters""" + self.partitioner = None + """The most recent trained partitioner""" + + self.fts_method = kwargs.get('fts_method', None) + """The FTS method to be called when a new model is build""" + self.fts_params = kwargs.get('fts_params', {}) + """The FTS method specific parameters""" + self.model = None + """The most recent trained model""" + + self.window_length = kwargs.get('window_length',100) + """The memory window length""" + self.auto_update = False + """If true the model is updated at each time and not recreated""" + self.is_high_order = True + +
    [docs] def train(self, data, **kwargs): + self.partitioner = self.partitioner_method(data=data, **self.partitioner_params) + self.model = self.fts_method(partitioner=self.partitioner, order=self.order, **self.fts_params) + self.model.fit(data, **kwargs)
    + +
    [docs] def forecast(self, data, **kwargs): + l = len(data) + + horizon = self.window_length + self.order + + ret = [] + + for k in np.arange(horizon, l): + _train = data[k - horizon: k - self.order] + _test = data[k - self.order: k] + + if self.auto_update: + self.model.train(_train) + else: + self.train(_train, **kwargs) + + ret.extend(self.model.predict(_test, **kwargs)) + + return ret
    + + def __str__(self): + """String representation of the model""" + + return str(self.model) + + def __len__(self): + """ + The length (number of rules) of the model + + :return: number of rules + """ + return len(self.model)
    +
    + +
    +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/docs/build/html/_modules/pyFTS/models/multivariate/common.html b/docs/build/html/_modules/pyFTS/models/multivariate/common.html index 282a7d9..ac86f4e 100644 --- a/docs/build/html/_modules/pyFTS/models/multivariate/common.html +++ b/docs/build/html/_modules/pyFTS/models/multivariate/common.html @@ -77,7 +77,8 @@ from pyFTS.common import FuzzySet
    [docs]def fuzzyfy_instance(data_point, var): - return FuzzySet.fuzzyfy(data_point, var.partitioner, mode='sets', method='fuzzy', alpha_cut=var.alpha_cut)
    + fsets = FuzzySet.fuzzyfy(data_point, var.partitioner, mode='sets', method='fuzzy', alpha_cut=var.alpha_cut) + return [(var.name, fs) for fs in fsets]
    diff --git a/docs/build/html/_modules/pyFTS/models/seasonal/common.html b/docs/build/html/_modules/pyFTS/models/seasonal/common.html index 9141efd..767e7b7 100644 --- a/docs/build/html/_modules/pyFTS/models/seasonal/common.html +++ b/docs/build/html/_modules/pyFTS/models/seasonal/common.html @@ -162,12 +162,17 @@ """ def __init__(self, datepart, name, mf, parameters, centroid, alpha=1.0, **kwargs): - super(FuzzySet, self).__init__(name, mf, parameters, centroid, alpha, type = 'datetime', **kwargs) + super(FuzzySet, self).__init__(name, mf, parameters, centroid, alpha, + type=kwargs.get('type', 'datetime'), + **kwargs) self.datepart = datepart self.type = 'seasonal'
    [docs] def membership(self, x): - dp = strip_datepart(x, self.datepart) + if self.type == 'datetime': + dp = strip_datepart(x, self.datepart) + else: + dp = x return self.mf(dp, self.parameters) * self.alpha
    diff --git a/docs/build/html/_modules/pyFTS/models/seasonal/partitioner.html b/docs/build/html/_modules/pyFTS/models/seasonal/partitioner.html index 1057a6a..411e4a9 100644 --- a/docs/build/html/_modules/pyFTS/models/seasonal/partitioner.html +++ b/docs/build/html/_modules/pyFTS/models/seasonal/partitioner.html @@ -138,6 +138,17 @@ **kwargs)) tmp.centroid = c sets[set_name] = tmp + elif c == self.max - partlen: + tmp = Composite(set_name, superset=True) + tmp.append_set(FuzzySet(self.season, set_name, Membership.trimf, + [0.0000001, 0.0, + pl2], 0.0, alpha=.5, + **kwargs)) + tmp.append_set(FuzzySet(self.season, set_name, Membership.trimf, + [c - partlen, c, c + partlen], c, + **kwargs)) + tmp.centroid = c + sets[set_name] = tmp else: sets[set_name] = FuzzySet(self.season, set_name, Membership.trimf, [c - partlen, c, c + partlen], c, diff --git a/docs/build/html/_modules/pyFTS/models/seasonal/sfts.html b/docs/build/html/_modules/pyFTS/models/seasonal/sfts.html index 847c2cd..413667d 100644 --- a/docs/build/html/_modules/pyFTS/models/seasonal/sfts.html +++ b/docs/build/html/_modules/pyFTS/models/seasonal/sfts.html @@ -164,7 +164,15 @@ ret.append(np.percentile(mp, 50)) - return ret
    + return ret + + def __str__(self): + """String representation of the model""" + + tmp = self.name + ":\n" + for r in self.flrgs: + tmp = tmp + str(self.flrgs[r]) + "\n" + return tmp diff --git a/docs/build/html/_modules/pyFTS/partitioners/Entropy.html b/docs/build/html/_modules/pyFTS/partitioners/Entropy.html index d2c31cc..b6c514b 100644 --- a/docs/build/html/_modules/pyFTS/partitioners/Entropy.html +++ b/docs/build/html/_modules/pyFTS/partitioners/Entropy.html @@ -116,7 +116,7 @@ if len(data) < 2: return None count = 1 - ndata = list(set(data)) + ndata = list(set(np.array(data).flatten())) ndata.sort() l = len(ndata) threshold = 0 diff --git a/docs/build/html/_modules/pyFTS/partitioners/partitioner.html b/docs/build/html/_modules/pyFTS/partitioners/partitioner.html index 5c705a6..0f0672b 100644 --- a/docs/build/html/_modules/pyFTS/partitioners/partitioner.html +++ b/docs/build/html/_modules/pyFTS/partitioners/partitioner.html @@ -128,7 +128,7 @@ self.min = float(_min * 1.1 if _min < 0 else _min * 0.9) - _max = max(ndata) + _max = np.nanmax(ndata) self.max = float(_max * 1.1 if _max > 0 else _max * 0.9) self.sets = self.build(ndata) diff --git a/docs/build/html/_modules/pyFTS/probabilistic/ProbabilityDistribution.html b/docs/build/html/_modules/pyFTS/probabilistic/ProbabilityDistribution.html index cbe2d27..dddb95b 100644 --- a/docs/build/html/_modules/pyFTS/probabilistic/ProbabilityDistribution.html +++ b/docs/build/html/_modules/pyFTS/probabilistic/ProbabilityDistribution.html @@ -256,7 +256,8 @@
    [docs] def cumulative(self, values): """ - Return the cumulative probability densities for the input values + Return the cumulative probability densities for the input values, + such that F(x) = P(X <= x) :param values: A list of input values :return: The cumulative probability densities for the input values @@ -275,7 +276,8 @@
    [docs] def quantile(self, values): """ - Return the quantile values for the input values + Return the Universe of Discourse values in relation to the quantile input values, + such that Q(tau) = min( {x | F(x) >= tau }) :param values: input values :return: The list of the quantile values for the input values @@ -296,7 +298,7 @@
    [docs] def entropy(self): """ - Return the entropy of the probability distribution, H[X] = + Return the entropy of the probability distribution, H(P) = E[ -ln P(X) ] = - ∑ P(x) log ( P(x) ) :return:the entropy of the probability distribution """ @@ -306,7 +308,8 @@
    [docs] def crossentropy(self,q): """ - Cross entropy between the actual probability distribution and the informed one. + Cross entropy between the actual probability distribution and the informed one, + H(P,Q) = - ∑ P(x) log ( Q(x) ) :param q: a probabilistic.ProbabilityDistribution object :return: Cross entropy between this probability distribution and the given distribution @@ -318,6 +321,7 @@
    [docs] def kullbackleiblerdivergence(self,q): """ Kullback-Leibler divergence between the actual probability distribution and the informed one. + DKL(P || Q) = - ∑ P(x) log( P(X) / Q(x) ) :param q: a probabilistic.ProbabilityDistribution object :return: Kullback-Leibler divergence @@ -328,7 +332,7 @@
    [docs] def empiricalloglikelihood(self): """ - Empirical Log Likelihood of the probability distribution + Empirical Log Likelihood of the probability distribution, L(P) = ∑ log( P(x) ) :return: """ diff --git a/docs/build/html/_sources/pyFTS.models.incremental.rst.txt b/docs/build/html/_sources/pyFTS.models.incremental.rst.txt new file mode 100644 index 0000000..ae8b9ba --- /dev/null +++ b/docs/build/html/_sources/pyFTS.models.incremental.rst.txt @@ -0,0 +1,24 @@ +pyFTS.models.incremental package +============================= + +Module contents +--------------- + +.. automodule:: pyFTS.models.incremental + :members: + :undoc-members: + :show-inheritance: + + +Submodules +---------- + +pyFTS.models.incremental.Retrainer module +------------------------------------- + +.. automodule:: pyFTS.models.incremental.Retrainer + :members: + :undoc-members: + :show-inheritance: + + diff --git a/docs/build/html/_sources/pyFTS.models.rst.txt b/docs/build/html/_sources/pyFTS.models.rst.txt index 3fa8c77..d35f88c 100644 --- a/docs/build/html/_sources/pyFTS.models.rst.txt +++ b/docs/build/html/_sources/pyFTS.models.rst.txt @@ -16,6 +16,7 @@ Subpackages .. toctree:: pyFTS.models.ensemble + pyFTS.models.incremental pyFTS.models.multivariate pyFTS.models.nonstationary pyFTS.models.seasonal diff --git a/docs/build/html/genindex.html b/docs/build/html/genindex.html index cf59e77..dbf7dc8 100644 --- a/docs/build/html/genindex.html +++ b/docs/build/html/genindex.html @@ -117,7 +117,11 @@
  • AllMethodEnsembleFTS (class in pyFTS.models.ensemble.ensemble)
  • alpha (pyFTS.common.FuzzySet.FuzzySet attribute) + +
  • alpha_cut (pyFTS.common.fts.FTS attribute)
  • analytic_tabular_dataframe() (in module pyFTS.benchmarks.Util) @@ -213,7 +217,11 @@
  • around() (pyFTS.common.SortedCollection.SortedCollection method)
  • auto_update (pyFTS.common.fts.FTS attribute) + +
  • averageloglikelihood() (pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution method)
  • @@ -508,6 +516,8 @@
  • (pyFTS.models.hofts.HighOrderFTS method)
  • (pyFTS.models.hwang.HighOrderFTS method) +
  • +
  • (pyFTS.models.incremental.Retrainer.Retrainer method)
  • (pyFTS.models.ismailefendi.ImprovedWeightedFTS method)
  • @@ -609,6 +619,10 @@
  • format_data() (pyFTS.models.multivariate.mvfts.MVFTS method)
  • FTS (class in pyFTS.common.fts) +
  • +
  • fts_method (pyFTS.models.incremental.Retrainer.Retrainer attribute) +
  • +
  • fts_params (pyFTS.models.incremental.Retrainer.Retrainer attribute)
  • fuzzify() (in module pyFTS.models.nonstationary.common)
  • @@ -1037,6 +1051,8 @@
  • interval_dataframe_synthetic_columns() (in module pyFTS.benchmarks.Util)
  • interval_heuristic() (pyFTS.models.pwfts.ProbabilisticWeightedFTS method) +
  • +
  • interval_method (pyFTS.models.ensemble.ensemble.EnsembleFTS attribute)
  • interval_quantile() (pyFTS.models.pwfts.ProbabilisticWeightedFTS method)
  • @@ -1163,6 +1179,8 @@
  • minute_of_week (pyFTS.models.seasonal.common.DateTime attribute)
  • minute_of_year (pyFTS.models.seasonal.common.DateTime attribute) +
  • +
  • model (pyFTS.models.incremental.Retrainer.Retrainer attribute)
  • models (pyFTS.models.ensemble.ensemble.EnsembleFTS attribute)
  • @@ -1251,6 +1269,14 @@
  • Partitioner (class in pyFTS.partitioners.partitioner)
  • partitioner (pyFTS.common.fts.FTS attribute) + +
  • +
  • partitioner_method (pyFTS.models.incremental.Retrainer.Retrainer attribute) +
  • +
  • partitioner_params (pyFTS.models.incremental.Retrainer.Retrainer attribute)
  • partitions (pyFTS.partitioners.partitioner.Partitioner attribute)
  • @@ -1339,6 +1365,8 @@
  • point_expected_value() (pyFTS.models.pwfts.ProbabilisticWeightedFTS method)
  • point_heuristic() (pyFTS.models.pwfts.ProbabilisticWeightedFTS method) +
  • +
  • point_method (pyFTS.models.ensemble.ensemble.EnsembleFTS attribute)
  • point_to_interval() (pyFTS.benchmarks.quantreg.QuantileRegression method)
  • @@ -1397,11 +1425,11 @@
  • pyFTS.benchmarks.quantreg (module)
  • pyFTS.benchmarks.ResidualAnalysis (module) -
  • -
  • pyFTS.benchmarks.Util (module)
  • -
  • rhs_conditional_probability() (pyFTS.models.pwfts.ProbabilisticWeightedFLRG method) -
  • +
  • pyFTS.models.incremental package +
  • pyFTS.models.multivariate package
    • Submodules
    • pyFTS.models.multivariate.FLR module
    • diff --git a/docs/build/html/pyFTS.models.ensemble.html b/docs/build/html/pyFTS.models.ensemble.html index cbca2b1..160812b 100644 --- a/docs/build/html/pyFTS.models.ensemble.html +++ b/docs/build/html/pyFTS.models.ensemble.html @@ -28,7 +28,7 @@ - + + + + + +
      +
      +
      +
      + +
      +

      pyFTS.models.incremental package

      +
      +

      Module contents

      +

      FTS methods with incremental/online learning

      +
      +
      +

      Submodules

      +
      +
      +

      pyFTS.models.incremental.Retrainer module

      +

      Meta model that wraps another FTS method and continously retrain it using a data window with the most recent data

      +
      +
      +class pyFTS.models.incremental.Retrainer.Retrainer(**kwargs)[source]
      +

      Bases: pyFTS.common.fts.FTS

      +

      Meta model for incremental/online learning

      +
      +
      +auto_update = None
      +

      If true the model is updated at each time and not recreated

      +
      + +
      +
      +forecast(data, **kwargs)[source]
      +

      Point forecast one step ahead

      + +++ + + + + + +
      Parameters:
        +
      • data – time series data with the minimal length equal to the max_lag of the model
      • +
      • kwargs – model specific parameters
      • +
      +
      Returns:

      a list with the forecasted values

      +
      +
      + +
      +
      +fts_method = None
      +

      The FTS method to be called when a new model is build

      +
      + +
      +
      +fts_params = None
      +

      The FTS method specific parameters

      +
      + +
      +
      +model = None
      +

      The most recent trained model

      +
      + +
      +
      +partitioner = None
      +

      The most recent trained partitioner

      +
      + +
      +
      +partitioner_method = None
      +

      The partitioner method to be called when a new model is build

      +
      + +
      +
      +partitioner_params = None
      +

      The partitioner method parameters

      +
      + +
      +
      +train(data, **kwargs)[source]
      +

      Method specific parameter fitting

      + +++ + + + +
      Parameters:
        +
      • data – training time series data
      • +
      • kwargs – Method specific parameters
      • +
      +
      +
      + +
      +
      +window_length = None
      +

      The memory window length

      +
      + +
      + +
      +
      + + +
      +
      +
      +
      +
      + + + + \ No newline at end of file diff --git a/docs/build/html/pyFTS.models.multivariate.html b/docs/build/html/pyFTS.models.multivariate.html index efa4fca..7f8ad8d 100644 --- a/docs/build/html/pyFTS.models.multivariate.html +++ b/docs/build/html/pyFTS.models.multivariate.html @@ -29,7 +29,7 @@ - +