diff --git a/benchmarks/benchmarks.py b/benchmarks/benchmarks.py index 4433970..0851771 100644 --- a/benchmarks/benchmarks.py +++ b/benchmarks/benchmarks.py @@ -17,7 +17,7 @@ from mpl_toolkits.mplot3d import Axes3D from pyFTS.partitioners import partitioner, Grid, Huarng, Entropy, FCM from pyFTS.benchmarks import Measures, naive, arima, ResidualAnalysis, ProbabilityDistribution, Util, quantreg from pyFTS.common import Membership, FuzzySet, FLR, Transformations, Util -from pyFTS import fts, song, chen, yu, ismailefendi, sadaei, hofts, hwang, pwfts, ifts, cheng, ensemble +from pyFTS import fts, song, chen, yu, ismailefendi, sadaei, hofts, hwang, pwfts, ifts, cheng, ensemble, hwang from copy import deepcopy colors = ['grey', 'rosybrown', 'maroon', 'red','orange', 'yellow', 'olive', 'green', @@ -38,7 +38,7 @@ def get_benchmark_point_methods(): def get_point_methods(): """Return all FTS methods for point forecasting""" return [song.ConventionalFTS, chen.ConventionalFTS, yu.WeightedFTS, ismailefendi.ImprovedWeightedFTS, - cheng.TrendWeightedFTS, sadaei.ExponentialyWeightedFTS, hofts.HighOrderFTS, + cheng.TrendWeightedFTS, sadaei.ExponentialyWeightedFTS, hofts.HighOrderFTS, hwang.HighOrderFTS, pwfts.ProbabilisticWeightedFTS] diff --git a/chen.py b/chen.py index 47ccacd..e796689 100644 --- a/chen.py +++ b/chen.py @@ -1,3 +1,9 @@ +""" +First Order Conventional Fuzzy Time Series by Chen (1996) + +S.-M. Chen, “Forecasting enrollments based on fuzzy time series,” Fuzzy Sets Syst., vol. 81, no. 3, pp. 311–319, 1996. +""" + import numpy as np from pyFTS.common import FuzzySet, FLR from pyFTS import fts diff --git a/cheng.py b/cheng.py index 97c92a9..f2ee57f 100644 --- a/cheng.py +++ b/cheng.py @@ -1,12 +1,21 @@ +""" +Trend Weighted Fuzzy Time Series by Cheng, Chen and Wu (2009) + +C.-H. Cheng, Y.-S. Chen, and Y.-L. Wu, “Forecasting innovation diffusion of products using trend-weighted fuzzy time-series model,” +Expert Syst. Appl., vol. 36, no. 2, pp. 1826–1832, 2009. +""" + import numpy as np from pyFTS.common import FuzzySet,FLR from pyFTS import fts, yu -class TrendWeightedFLRG(yu.WeightedFTS): - """First Order Trend Weighted Fuzzy Logical Relationship Group""" +class TrendWeightedFLRG(yu.WeightedFLRG): + """ + First Order Trend Weighted Fuzzy Logical Relationship Group + """ def __init__(self, LHS, **kwargs): - super(TrendWeightedFTS, self).__init__(LHS) + super(TrendWeightedFLRG, self).__init__(LHS) def weights(self): count_nochange = 0.0 @@ -16,10 +25,10 @@ class TrendWeightedFLRG(yu.WeightedFTS): for c in self.RHS: tmp = 0 - if self.RHS.midpoint == c.midpoint: + if self.LHS.centroid == c.centroid: count_nochange += 1.0 tmp = count_nochange - elif self.RHS.midpoint > c.midpoint: + elif self.LHS.centroid > c.centroid: count_down += 1.0 tmp = count_down else: @@ -34,7 +43,7 @@ class TrendWeightedFLRG(yu.WeightedFTS): class TrendWeightedFTS(yu.WeightedFTS): """First Order Trend Weighted Fuzzy Time Series""" def __init__(self, name, **kwargs): - super(TrendWeightedFTS, self).__init__(1, "TWFTS " + name) + super(TrendWeightedFTS, self).__init__("TWFTS " + name) self.name = "Trend Weighted FTS" self.detail = "Cheng" @@ -44,6 +53,6 @@ class TrendWeightedFTS(yu.WeightedFTS): if flr.LHS.name in flrgs: flrgs[flr.LHS.name].append(flr.RHS) else: - flrgs[flr.LHS.name] = TrendWeightedFLRG(flr.LHS); + flrgs[flr.LHS.name] = TrendWeightedFLRG(flr.LHS) flrgs[flr.LHS.name].append(flr.RHS) return (flrgs) \ No newline at end of file diff --git a/hofts.py b/hofts.py index 14776b9..a857c6c 100644 --- a/hofts.py +++ b/hofts.py @@ -1,3 +1,10 @@ +""" +Simple High Order extension of Conventional FTS by Chen (1996) + +[1] S.-M. Chen, “Forecasting enrollments based on fuzzy time series,” +Fuzzy Sets Syst., vol. 81, no. 3, pp. 311–319, 1996. +""" + import numpy as np from pyFTS.common import FuzzySet,FLR from pyFTS import fts diff --git a/hwang.py b/hwang.py index e67249f..0063f9f 100644 --- a/hwang.py +++ b/hwang.py @@ -1,3 +1,10 @@ +""" +High Order Fuzzy Time Series by Hwang, Chen and Lee (1998) + +Jeng-Ren Hwang, Shyi-Ming Chen, and Chia-Hoang Lee, “Handling forecasting problems using fuzzy time series,” +Fuzzy Sets Syst., no. 100, pp. 217–228, 1998. +""" + import numpy as np from pyFTS.common import FuzzySet,FLR,Transformations from pyFTS import fts diff --git a/ismailefendi.py b/ismailefendi.py index d5658de..4a0f9de 100644 --- a/ismailefendi.py +++ b/ismailefendi.py @@ -1,3 +1,10 @@ +""" +First Order Improved Weighted Fuzzy Time Series by Efendi, Ismail and Deris (2013) + +R. Efendi, Z. Ismail, and M. M. Deris, “Improved weight Fuzzy Time Series as used in the exchange rates forecasting of +US Dollar to Ringgit Malaysia,” Int. J. Comput. Intell. Appl., vol. 12, no. 1, p. 1350005, 2013. +""" + import numpy as np from pyFTS.common import FuzzySet,FLR from pyFTS import fts diff --git a/sadaei.py b/sadaei.py index eb9b9b8..438761b 100644 --- a/sadaei.py +++ b/sadaei.py @@ -1,3 +1,10 @@ +""" +First Order Exponentialy Weighted Fuzzy Time Series by Sadaei et al. (2013) + +H. J. Sadaei, R. Enayatifar, A. H. Abdullah, and A. Gani, “Short-term load forecasting using a hybrid model with a +refined exponentially weighted fuzzy time series and an improved harmony search,” Int. J. Electr. Power Energy Syst., vol. 62, no. from 2005, pp. 118–129, 2014. +""" + import numpy as np from pyFTS.common import FuzzySet,FLR from pyFTS import fts diff --git a/sfts.py b/sfts.py index 982c65c..a475e5a 100644 --- a/sfts.py +++ b/sfts.py @@ -1,3 +1,11 @@ +""" +Simple First Order Seasonal Fuzzy Time Series implementation of Song (1999) based of Conventional FTS by Chen (1996) + +Q. Song, “Seasonal forecasting in fuzzy time series,” Fuzzy sets Syst., vol. 107, pp. 235–236, 1999. + +S.-M. Chen, “Forecasting enrollments based on fuzzy time series,” Fuzzy Sets Syst., vol. 81, no. 3, pp. 311–319, 1996. +""" + import numpy as np from pyFTS.common import FuzzySet,FLR from pyFTS import fts diff --git a/song.py b/song.py index 391cab5..08deb07 100644 --- a/song.py +++ b/song.py @@ -1,9 +1,16 @@ +""" +First Order Traditional Fuzzy Time Series method by Song & Chissom (1993) + +Q. Song and B. S. Chissom, “Fuzzy time series and its models,” Fuzzy Sets Syst., vol. 54, no. 3, pp. 269–277, 1993. +""" + import numpy as np from pyFTS.common import FuzzySet, FLR from pyFTS import fts + class ConventionalFTS(fts.FTS): - """Conventional Fuzzy Time Series""" + """Traditional Fuzzy Time Series""" def __init__(self, name, **kwargs): super(ConventionalFTS, self).__init__(1, "FTS " + name) self.name = "Traditional FTS" diff --git a/tests/general.py b/tests/general.py index 425e006..30576f4 100644 --- a/tests/general.py +++ b/tests/general.py @@ -19,18 +19,18 @@ from numpy import random os.chdir("/home/petronio/dados/Dropbox/Doutorado/Codigos/") -enrollments = pd.read_csv("DataSets/Enrollments.csv", sep=";") -enrollments = np.array(enrollments["Enrollments"]) +#enrollments = pd.read_csv("DataSets/Enrollments.csv", sep=";") +#enrollments = np.array(enrollments["Enrollments"]) -from pyFTS import song +#from pyFTS import song -enrollments_fs = Grid.GridPartitioner(enrollments, 10).sets +#enrollments_fs = Grid.GridPartitioner(enrollments, 10).sets -model = song.ConventionalFTS('') -model.train(enrollments,enrollments_fs) -teste = model.forecast(enrollments) +#model = song.ConventionalFTS('') +#model.train(enrollments,enrollments_fs) +#teste = model.forecast(enrollments) -print(teste) +#print(teste) #print(FCM.FCMPartitionerTrimf.__module__) @@ -39,8 +39,8 @@ print(teste) #gauss_teste = random.normal(0,1.0,400) -#taiexpd = pd.read_csv("DataSets/TAIEX.csv", sep=",") -#taiex = np.array(taiexpd["avg"][:5000]) +taiexpd = pd.read_csv("DataSets/TAIEX.csv", sep=",") +taiex = np.array(taiexpd["avg"][:5000]) #from statsmodels.tsa.arima_model import ARIMA as stats_arima from statsmodels.tsa.tsatools import lagmat @@ -52,7 +52,7 @@ from statsmodels.tsa.tsatools import lagmat #print(lag) #print(a) -#from pyFTS.benchmarks import distributed_benchmarks as bchmk +from pyFTS.benchmarks import distributed_benchmarks as bchmk #from pyFTS.benchmarks import parallel_benchmarks as bchmk #from pyFTS.benchmarks import benchmarks as bchmk #from pyFTS.benchmarks import arima @@ -66,11 +66,11 @@ from statsmodels.tsa.tsatools import lagmat #bchmk.teste(taiex,['192.168.0.109', '192.168.0.101']) -#bchmk.point_sliding_window(taiex,2000,train=0.8, #models=[yu.WeightedFTS], # # -# partitioners=[Grid.GridPartitioner], #Entropy.EntropyPartitioner], # FCM.FCMPartitioner, ], -# partitions= np.arange(10,200,step=5), #transformation=diff, -# dump=True, save=False, file="experiments/nasdaq_point_distributed.csv", -# nodes=['192.168.1.42']) #, depends=[hofts, ifts]) +bchmk.point_sliding_window(taiex,2000,train=0.8, #models=[yu.WeightedFTS], # # + partitioners=[Grid.GridPartitioner], #Entropy.EntropyPartitioner], # FCM.FCMPartitioner, ], + partitions= np.arange(10,200,step=5), #transformation=diff, + dump=True, save=True, file="experiments/taiex_point_distributed.csv", + nodes=['192.168.0.102', '192.168.0.109']) #, depends=[hofts, ifts]) #bchmk.testa(taiex,[10,20],partitioners=[Grid.GridPartitioner], nodes=['192.168.0.109', '192.168.0.101']) diff --git a/yu.py b/yu.py index e4225f2..42509c5 100644 --- a/yu.py +++ b/yu.py @@ -1,3 +1,10 @@ +""" +First Order Weighted Fuzzy Time Series by Yu(2005) + +H.-K. Yu, “Weighted fuzzy time series models for TAIEX forecasting,” +Phys. A Stat. Mech. its Appl., vol. 349, no. 3, pp. 609–624, 2005. +""" + import numpy as np from pyFTS.common import FuzzySet,FLR from pyFTS import fts