From 3f435222aca38a845a9b7e73f205603123b1a98e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=C3=B4nio=20C=C3=A2ndido?= Date: Tue, 30 Oct 2018 19:00:51 -0300 Subject: [PATCH] Bugfixes --- pyFTS/models/seasonal/sfts.py | 8 ++++++++ pyFTS/partitioners/Entropy.py | 2 +- pyFTS/partitioners/partitioner.py | 2 +- pyFTS/tests/general.py | 21 +++++++++++++++++++-- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/pyFTS/models/seasonal/sfts.py b/pyFTS/models/seasonal/sfts.py index f93aa91..19faafc 100644 --- a/pyFTS/models/seasonal/sfts.py +++ b/pyFTS/models/seasonal/sfts.py @@ -91,3 +91,11 @@ class SeasonalFTS(fts.FTS): ret.append(np.percentile(mp, 50)) 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/pyFTS/partitioners/Entropy.py b/pyFTS/partitioners/Entropy.py index f183646..914c70f 100644 --- a/pyFTS/partitioners/Entropy.py +++ b/pyFTS/partitioners/Entropy.py @@ -42,7 +42,7 @@ def bestSplit(data, npart): 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/pyFTS/partitioners/partitioner.py b/pyFTS/partitioners/partitioner.py index 6275daa..fe58aea 100644 --- a/pyFTS/partitioners/partitioner.py +++ b/pyFTS/partitioners/partitioner.py @@ -54,7 +54,7 @@ class Partitioner(object): 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/pyFTS/tests/general.py b/pyFTS/tests/general.py index e3e2199..821c394 100644 --- a/pyFTS/tests/general.py +++ b/pyFTS/tests/general.py @@ -9,13 +9,30 @@ import matplotlib.pylab as plt import pandas as pd from pyFTS.common import Util as cUtil, FuzzySet -from pyFTS.partitioners import Grid, Util as pUtil +from pyFTS.partitioners import Grid, Entropy, Util as pUtil from pyFTS.benchmarks import benchmarks as bchmk from pyFTS.models import chen, yu, cheng, ismailefendi, hofts, pwfts from pyFTS.common import Transformations tdiff = Transformations.Differential(1) +data = pd.read_csv('/home/petronio/Downloads/priceHong').values + +split = 24 * 800 +train = data[:split].flatten() +test = data[split:].flatten() + +print(train) + +fs_grid = Grid.GridPartitioner(data=train,npart=25) +#fs_entr.plot(ax[1]) + +for method in [hofts.HighOrderFTS, pwfts.ProbabilisticWeightedFTS]: + for order in [2,3]: + model = method(partitioner=fs_grid, order=order) + model.fit(train) + +''' from pyFTS.data import TAIEX, SP500, NASDAQ dataset = TAIEX.get_data() @@ -30,7 +47,7 @@ model.fit(dataset[:800]) print(model) ret = model.predict([5000.00, 5200.00, 5400.00], explain=True) - +''' ''' #dataset = SP500.get_data()[11500:16000] #dataset = NASDAQ.get_data()