- Issue #3 - Code documentation with PEP 257 compliance

This commit is contained in:
Petrônio Cândido de Lima e Silva 2017-05-07 11:41:31 -03:00
parent cbfbf47f54
commit ea7a0bbd62
11 changed files with 91 additions and 26 deletions

View File

@ -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]

View File

@ -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. 311319, 1996.
"""
import numpy as np
from pyFTS.common import FuzzySet, FLR
from pyFTS import fts

View File

@ -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. 18261832, 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)

View File

@ -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. 311319, 1996.
"""
import numpy as np
from pyFTS.common import FuzzySet,FLR
from pyFTS import fts

View File

@ -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. 217228, 1998.
"""
import numpy as np
from pyFTS.common import FuzzySet,FLR,Transformations
from pyFTS import fts

View File

@ -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

View File

@ -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. 118129, 2014.
"""
import numpy as np
from pyFTS.common import FuzzySet,FLR
from pyFTS import fts

View File

@ -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. 235236, 1999.
S.-M. Chen, Forecasting enrollments based on fuzzy time series, Fuzzy Sets Syst., vol. 81, no. 3, pp. 311319, 1996.
"""
import numpy as np
from pyFTS.common import FuzzySet,FLR
from pyFTS import fts

View File

@ -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. 269277, 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"

View File

@ -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'])

7
yu.py
View File

@ -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. 609624, 2005.
"""
import numpy as np
from pyFTS.common import FuzzySet,FLR
from pyFTS import fts