From 5563af3079a91aac1717557224f8629370ea9f22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=C3=B4nio=20C=C3=A2ndido?= Date: Mon, 14 May 2018 00:16:19 -0300 Subject: [PATCH] Bugfixes --- pyFTS/benchmarks/Measures.py | 1 + pyFTS/models/pwfts.py | 15 ++++++++++---- pyFTS/tests/general.py | 40 ++++++++++++++++++++---------------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/pyFTS/benchmarks/Measures.py b/pyFTS/benchmarks/Measures.py index b9ead5f..63593ad 100644 --- a/pyFTS/benchmarks/Measures.py +++ b/pyFTS/benchmarks/Measures.py @@ -276,6 +276,7 @@ def heavyside_cdf(bins, targets): df = pd.DataFrame(ret, columns=bins) return df + def crps(targets, densities): ''' Continuous Ranked Probability Score diff --git a/pyFTS/models/pwfts.py b/pyFTS/models/pwfts.py index fe93abb..2796da3 100644 --- a/pyFTS/models/pwfts.py +++ b/pyFTS/models/pwfts.py @@ -393,14 +393,19 @@ class ProbabilisticWeightedFTS(ifts.IntervalFTS): return point <= lower_set.lower or point >= upper_set.upper def forecast_ahead(self, data, steps, **kwargs): - ret = [data[k] for k in np.arange(len(data) - self.order, len(data))] - for k in np.arange(self.order - 1, steps): + l = len(data) + + start = kwargs.get('start', self.order) + + ret = data[start - self.order: start].tolist() + + for k in np.arange(self.order, steps+self.order): if self.__check_point_bounds(ret[-1]) : ret.append(ret[-1]) else: - mp = self.forecast([ret[x] for x in np.arange(k - self.order, k)], **kwargs) + mp = self.forecast(ret[k - self.order: k], **kwargs) ret.append(mp[0]) return ret[self.order:] @@ -422,8 +427,10 @@ class ProbabilisticWeightedFTS(ifts.IntervalFTS): sample = data[start - self.order: start] ret = [[k, k] for k in sample] + + ret.append(self.forecast_interval(sample)[0]) - for k in np.arange(self.order, steps+self.order): + for k in np.arange(self.order+1, steps+self.order): if len(ret) > 0 and self.__check_interval_bounds(ret[-1]): ret.append(ret[-1]) diff --git a/pyFTS/tests/general.py b/pyFTS/tests/general.py index bc8a729..855ef69 100644 --- a/pyFTS/tests/general.py +++ b/pyFTS/tests/general.py @@ -50,7 +50,7 @@ bchmk.sliding_window_benchmarks(dataset, 1000, train=0.8, inc=0.2, progress=False, type="point", #steps_ahead=[1,2,4,6,8,10], distributed=True, nodes=['192.168.0.110', '192.168.0.107', '192.168.0.106'], - file="benchmarks.db", dataset="NASDAQ", tag="comparisons") + file="benchmarks.db", dataset="TAIEX", tag="comparisons") @@ -80,7 +80,7 @@ print(Measures.get_distribution_statistics(dataset[800:1000], model, steps_ahead ''' #''' -types = ['interval']#['point','interval','distribution'] +types = ['point','interval','distribution'] benchmark_methods=[[arima.ARIMA for k in range(8)] + [quantreg.QuantileRegression for k in range(4)]] ''' benchmark_methods=[ @@ -136,33 +136,37 @@ benchmark_methods_parameters= [ ] ]''' dataset_name = "SP500" -tag = "comparisons" +tag = "ahead2" from pyFTS.benchmarks import arima, naive, quantreg for ct, type in enumerate(types): - bchmk.sliding_window_benchmarks(dataset, 1000, train=0.8, inc=0.2, - benchmark_models=True, - benchmark_methods=benchmark_methods[ct], - benchmark_methods_parameters=benchmark_methods_parameters[ct], - transformations=[None], - orders=[1,2,3], - partitions=np.arange(15, 85, 5), - progress=False, type=type, - distributed=True, nodes=['192.168.0.110', '192.168.0.107','192.168.0.106'], - file="benchmarks.db", dataset=dataset_name, tag=tag) bchmk.sliding_window_benchmarks(dataset, 1000, train=0.8, inc=0.2, - benchmark_models=True, - benchmark_methods=benchmark_methods[ct], - benchmark_methods_parameters=benchmark_methods_parameters[ct], + methods=[pwfts.ProbabilisticWeightedFTS], + benchmark_models=False, + #benchmark_methods=benchmark_methods[ct], + #benchmark_methods_parameters=benchmark_methods_parameters[ct], transformations=[tdiff], - orders=[1, 2, 3], - partitiTAIEXons=np.arange(3, 35, 2), + orders=[1], #, 2, 3], + partitions=[5], #np.arange(3, 35, 2), progress=False, type=type, + steps_ahead=[2, 4, 6, 8, 10], distributed=True, nodes=['192.168.0.110', '192.168.0.107', '192.168.0.106'], file="benchmarks.db", dataset=dataset_name, tag=tag) + bchmk.sliding_window_benchmarks(dataset, 1000, train=0.8, inc=0.2, + methods=[pwfts.ProbabilisticWeightedFTS], + benchmark_models=False, + #benchmark_methods=benchmark_methods[ct], + #benchmark_methods_parameters=benchmark_methods_parameters[ct], + transformations=[None], + orders=[1], #,2,3], + partitions=[30], #np.arange(15, 85, 5), + progress=False, type=type, + steps_ahead=[2, 4, 6, 8, 10], + distributed=True, nodes=['192.168.0.110', '192.168.0.107','192.168.0.106'], + file="benchmarks.db", dataset=dataset_name, tag=tag) #'''