From 9089310187a545635d4d063cf1a646b434748961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=C3=B4nio=20C=C3=A2ndido?= Date: Thu, 2 Aug 2018 18:29:52 -0300 Subject: [PATCH] CVFTS bugfixes --- pyFTS/benchmarks/benchmarks.py | 2 -- pyFTS/models/nonstationary/cvfts.py | 15 +++++++++------ pyFTS/models/nonstationary/partitioners.py | 1 - pyFTS/partitioners/partitioner.py | 10 ++-------- pyFTS/tests/nonstationary.py | 18 ++++++++++-------- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/pyFTS/benchmarks/benchmarks.py b/pyFTS/benchmarks/benchmarks.py index bd566aa..ef0859b 100644 --- a/pyFTS/benchmarks/benchmarks.py +++ b/pyFTS/benchmarks/benchmarks.py @@ -280,8 +280,6 @@ def sliding_window_benchmarks(data, windowsize, train=0.8, **kwargs): if progress: progressbar.update(1) try: - print(model.shortname, model.order, partitioner.name, - partitioner.partitions, str(partitioner.transformation)) job = experiment_method(deepcopy(model), deepcopy(partitioner), train, test, **kwargs) synthesis_method(dataset, tag, job, conn) except Exception as ex: diff --git a/pyFTS/models/nonstationary/cvfts.py b/pyFTS/models/nonstationary/cvfts.py index d64cc9a..c93afd2 100644 --- a/pyFTS/models/nonstationary/cvfts.py +++ b/pyFTS/models/nonstationary/cvfts.py @@ -101,7 +101,7 @@ class ConditionalVarianceFTS(hofts.HighOrderFTS): _range = (_max - _min)/2 - translate = np.linspace(_min, _max, self.partitioner.partitions) + translate = np.linspace(_min, _max, len(self.partitioner.sets)) var = np.std(self.residuals) @@ -111,7 +111,7 @@ class ConditionalVarianceFTS(hofts.HighOrderFTS): location = [_range + w + loc + k for k in np.linspace(-var,var) for w in translate] - perturb = [[location[k], var] for k in np.arange(0, self.partitioner.partitions)] + perturb = [[location[k], var] for k in np.arange(len(self.partitioner.sets))] return perturb @@ -138,11 +138,14 @@ class ConditionalVarianceFTS(hofts.HighOrderFTS): return perturb + def _fsset_key(self, ix): + return self.partitioner.ordered_sets[ix] + def _affected_sets(self, sample, perturb): - affected_sets = [[ct, self.sets[key].membership(sample, perturb[ct])] - for ct, key in enumerate(self.partitioner.ordered_sets) - if self.sets[key].membership(sample, perturb[ct]) > 0.0] + affected_sets = [[ct, self.sets[self._fsset_key(ct)].membership(sample, perturb[ct])] + for ct in np.arange(self.partitioner.partitions) + if self.sets[self._fsset_key(ct)].membership(sample, perturb[ct]) > 0.0] if len(affected_sets) == 0: if sample < self.partitioner.lower_set().get_lower(perturb[0]): @@ -167,7 +170,7 @@ class ConditionalVarianceFTS(hofts.HighOrderFTS): if not no_update: perturb = self.perturbation_factors(sample) else: - perturb = [[0, 1] for k in np.arange(0, self.partitioner.partitions)] + perturb = [[0, 1] for k in np.arange(len(self.partitioner.sets))] affected_sets = self._affected_sets(sample, perturb) diff --git a/pyFTS/models/nonstationary/partitioners.py b/pyFTS/models/nonstationary/partitioners.py index 55f5eb1..edb75d8 100644 --- a/pyFTS/models/nonstationary/partitioners.py +++ b/pyFTS/models/nonstationary/partitioners.py @@ -134,7 +134,6 @@ class SimpleNonStationaryPartitioner(partitioner.Partitioner): return {} - def simplenonstationary_gridpartitioner_builder(data, npart, transformation): from pyFTS.partitioners import Grid from pyFTS.models.nonstationary import perturbation, partitioners diff --git a/pyFTS/partitioners/partitioner.py b/pyFTS/partitioners/partitioner.py index 656ab28..08060f3 100644 --- a/pyFTS/partitioners/partitioner.py +++ b/pyFTS/partitioners/partitioner.py @@ -53,16 +53,10 @@ class Partitioner(object): ndata[ndata == -np.inf] = 0 _min = np.nanmin(ndata) - if _min < 0: - self.min = _min * 1.1 - else: - self.min = _min * 0.9 + self.min = float(_min * 1.1 if _min < 0 else _min * 0.9) _max = max(ndata) - if _max > 0: - self.max = _max * 1.1 - else: - self.max = _max * 0.9 + self.max = float(_max * 1.1 if _max > 0 else _max * 0.9) self.sets = self.build(ndata) diff --git a/pyFTS/tests/nonstationary.py b/pyFTS/tests/nonstationary.py index b4e74cf..18e4731 100644 --- a/pyFTS/tests/nonstationary.py +++ b/pyFTS/tests/nonstationary.py @@ -11,17 +11,17 @@ import pandas as pd from pyFTS.data import TAIEX, NASDAQ, SP500, artificial datasets = { - "TAIEX": TAIEX.get_data()[:4000], + #"TAIEX": TAIEX.get_data()[:4000], "SP500": SP500.get_data()[10000:14000], - "NASDAQ": NASDAQ.get_data()[:4000], + #"NASDAQ": NASDAQ.get_data()[:4000], # Incremental Mean and Incremental Variance - "IMIV": artificial.generate_gaussian_linear(1,0.2,0.2,0.05,it=100, num=40), + #"IMIV": artificial.generate_gaussian_linear(1,0.2,0.2,0.05,it=100, num=40), # Incremental Mean and Incremental Variance, lower bound equals to 0 - "IMIV0": artificial.generate_gaussian_linear(1,0.2,0.,0.05, vmin=0,it=100, num=40), + #"IMIV0": artificial.generate_gaussian_linear(1,0.2,0.,0.05, vmin=0,it=100, num=40), # Constant Mean and Incremental Variance - "CMIV": artificial.generate_gaussian_linear(5,0.1,0,0.02,it=100, num=40), + #"CMIV": artificial.generate_gaussian_linear(5,0.1,0,0.02,it=100, num=40), # Incremental Mean and Constant Variance - "IMCV": artificial.generate_gaussian_linear(1,0.6,0.1,0,it=100, num=40) + #"IMCV": artificial.generate_gaussian_linear(1,0.6,0.1,0,it=100, num=40) } train_split = 2000 @@ -34,9 +34,9 @@ tdiff = Transformations.Differential(1) boxcox = Transformations.BoxCox(0) transformations = { - 'None': None, + #'None': None, 'Differential(1)': tdiff, - 'BoxCox(0)': boxcox + #'BoxCox(0)': boxcox } from pyFTS.partitioners import Grid, Util as pUtil @@ -78,6 +78,8 @@ for ds in datasets.keys(): for ds in datasets.keys(): dataset = datasets[ds] + print(ds) + for tf in transformations.keys(): transformation = transformations[tf]