- Issue #3 - Code documentation with PEP 257 compliance
This commit is contained in:
parent
cbfbf47f54
commit
ea7a0bbd62
@ -17,7 +17,7 @@ from mpl_toolkits.mplot3d import Axes3D
|
|||||||
from pyFTS.partitioners import partitioner, Grid, Huarng, Entropy, FCM
|
from pyFTS.partitioners import partitioner, Grid, Huarng, Entropy, FCM
|
||||||
from pyFTS.benchmarks import Measures, naive, arima, ResidualAnalysis, ProbabilityDistribution, Util, quantreg
|
from pyFTS.benchmarks import Measures, naive, arima, ResidualAnalysis, ProbabilityDistribution, Util, quantreg
|
||||||
from pyFTS.common import Membership, FuzzySet, FLR, Transformations, Util
|
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
|
from copy import deepcopy
|
||||||
|
|
||||||
colors = ['grey', 'rosybrown', 'maroon', 'red','orange', 'yellow', 'olive', 'green',
|
colors = ['grey', 'rosybrown', 'maroon', 'red','orange', 'yellow', 'olive', 'green',
|
||||||
@ -38,7 +38,7 @@ def get_benchmark_point_methods():
|
|||||||
def get_point_methods():
|
def get_point_methods():
|
||||||
"""Return all FTS methods for point forecasting"""
|
"""Return all FTS methods for point forecasting"""
|
||||||
return [song.ConventionalFTS, chen.ConventionalFTS, yu.WeightedFTS, ismailefendi.ImprovedWeightedFTS,
|
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]
|
pwfts.ProbabilisticWeightedFTS]
|
||||||
|
|
||||||
|
|
||||||
|
6
chen.py
6
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
|
import numpy as np
|
||||||
from pyFTS.common import FuzzySet, FLR
|
from pyFTS.common import FuzzySet, FLR
|
||||||
from pyFTS import fts
|
from pyFTS import fts
|
||||||
|
23
cheng.py
23
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
|
import numpy as np
|
||||||
from pyFTS.common import FuzzySet,FLR
|
from pyFTS.common import FuzzySet,FLR
|
||||||
from pyFTS import fts, yu
|
from pyFTS import fts, yu
|
||||||
|
|
||||||
|
|
||||||
class TrendWeightedFLRG(yu.WeightedFTS):
|
class TrendWeightedFLRG(yu.WeightedFLRG):
|
||||||
"""First Order Trend Weighted Fuzzy Logical Relationship Group"""
|
"""
|
||||||
|
First Order Trend Weighted Fuzzy Logical Relationship Group
|
||||||
|
"""
|
||||||
def __init__(self, LHS, **kwargs):
|
def __init__(self, LHS, **kwargs):
|
||||||
super(TrendWeightedFTS, self).__init__(LHS)
|
super(TrendWeightedFLRG, self).__init__(LHS)
|
||||||
|
|
||||||
def weights(self):
|
def weights(self):
|
||||||
count_nochange = 0.0
|
count_nochange = 0.0
|
||||||
@ -16,10 +25,10 @@ class TrendWeightedFLRG(yu.WeightedFTS):
|
|||||||
|
|
||||||
for c in self.RHS:
|
for c in self.RHS:
|
||||||
tmp = 0
|
tmp = 0
|
||||||
if self.RHS.midpoint == c.midpoint:
|
if self.LHS.centroid == c.centroid:
|
||||||
count_nochange += 1.0
|
count_nochange += 1.0
|
||||||
tmp = count_nochange
|
tmp = count_nochange
|
||||||
elif self.RHS.midpoint > c.midpoint:
|
elif self.LHS.centroid > c.centroid:
|
||||||
count_down += 1.0
|
count_down += 1.0
|
||||||
tmp = count_down
|
tmp = count_down
|
||||||
else:
|
else:
|
||||||
@ -34,7 +43,7 @@ class TrendWeightedFLRG(yu.WeightedFTS):
|
|||||||
class TrendWeightedFTS(yu.WeightedFTS):
|
class TrendWeightedFTS(yu.WeightedFTS):
|
||||||
"""First Order Trend Weighted Fuzzy Time Series"""
|
"""First Order Trend Weighted Fuzzy Time Series"""
|
||||||
def __init__(self, name, **kwargs):
|
def __init__(self, name, **kwargs):
|
||||||
super(TrendWeightedFTS, self).__init__(1, "TWFTS " + name)
|
super(TrendWeightedFTS, self).__init__("TWFTS " + name)
|
||||||
self.name = "Trend Weighted FTS"
|
self.name = "Trend Weighted FTS"
|
||||||
self.detail = "Cheng"
|
self.detail = "Cheng"
|
||||||
|
|
||||||
@ -44,6 +53,6 @@ class TrendWeightedFTS(yu.WeightedFTS):
|
|||||||
if flr.LHS.name in flrgs:
|
if flr.LHS.name in flrgs:
|
||||||
flrgs[flr.LHS.name].append(flr.RHS)
|
flrgs[flr.LHS.name].append(flr.RHS)
|
||||||
else:
|
else:
|
||||||
flrgs[flr.LHS.name] = TrendWeightedFLRG(flr.LHS);
|
flrgs[flr.LHS.name] = TrendWeightedFLRG(flr.LHS)
|
||||||
flrgs[flr.LHS.name].append(flr.RHS)
|
flrgs[flr.LHS.name].append(flr.RHS)
|
||||||
return (flrgs)
|
return (flrgs)
|
7
hofts.py
7
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
|
import numpy as np
|
||||||
from pyFTS.common import FuzzySet,FLR
|
from pyFTS.common import FuzzySet,FLR
|
||||||
from pyFTS import fts
|
from pyFTS import fts
|
||||||
|
7
hwang.py
7
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
|
import numpy as np
|
||||||
from pyFTS.common import FuzzySet,FLR,Transformations
|
from pyFTS.common import FuzzySet,FLR,Transformations
|
||||||
from pyFTS import fts
|
from pyFTS import fts
|
||||||
|
@ -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
|
import numpy as np
|
||||||
from pyFTS.common import FuzzySet,FLR
|
from pyFTS.common import FuzzySet,FLR
|
||||||
from pyFTS import fts
|
from pyFTS import fts
|
||||||
|
@ -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
|
import numpy as np
|
||||||
from pyFTS.common import FuzzySet,FLR
|
from pyFTS.common import FuzzySet,FLR
|
||||||
from pyFTS import fts
|
from pyFTS import fts
|
||||||
|
8
sfts.py
8
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
|
import numpy as np
|
||||||
from pyFTS.common import FuzzySet,FLR
|
from pyFTS.common import FuzzySet,FLR
|
||||||
from pyFTS import fts
|
from pyFTS import fts
|
||||||
|
9
song.py
9
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
|
import numpy as np
|
||||||
from pyFTS.common import FuzzySet, FLR
|
from pyFTS.common import FuzzySet, FLR
|
||||||
from pyFTS import fts
|
from pyFTS import fts
|
||||||
|
|
||||||
|
|
||||||
class ConventionalFTS(fts.FTS):
|
class ConventionalFTS(fts.FTS):
|
||||||
"""Conventional Fuzzy Time Series"""
|
"""Traditional Fuzzy Time Series"""
|
||||||
def __init__(self, name, **kwargs):
|
def __init__(self, name, **kwargs):
|
||||||
super(ConventionalFTS, self).__init__(1, "FTS " + name)
|
super(ConventionalFTS, self).__init__(1, "FTS " + name)
|
||||||
self.name = "Traditional FTS"
|
self.name = "Traditional FTS"
|
||||||
|
@ -19,18 +19,18 @@ from numpy import random
|
|||||||
|
|
||||||
os.chdir("/home/petronio/dados/Dropbox/Doutorado/Codigos/")
|
os.chdir("/home/petronio/dados/Dropbox/Doutorado/Codigos/")
|
||||||
|
|
||||||
enrollments = pd.read_csv("DataSets/Enrollments.csv", sep=";")
|
#enrollments = pd.read_csv("DataSets/Enrollments.csv", sep=";")
|
||||||
enrollments = np.array(enrollments["Enrollments"])
|
#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 = song.ConventionalFTS('')
|
||||||
model.train(enrollments,enrollments_fs)
|
#model.train(enrollments,enrollments_fs)
|
||||||
teste = model.forecast(enrollments)
|
#teste = model.forecast(enrollments)
|
||||||
|
|
||||||
print(teste)
|
#print(teste)
|
||||||
|
|
||||||
|
|
||||||
#print(FCM.FCMPartitionerTrimf.__module__)
|
#print(FCM.FCMPartitionerTrimf.__module__)
|
||||||
@ -39,8 +39,8 @@ print(teste)
|
|||||||
#gauss_teste = random.normal(0,1.0,400)
|
#gauss_teste = random.normal(0,1.0,400)
|
||||||
|
|
||||||
|
|
||||||
#taiexpd = pd.read_csv("DataSets/TAIEX.csv", sep=",")
|
taiexpd = pd.read_csv("DataSets/TAIEX.csv", sep=",")
|
||||||
#taiex = np.array(taiexpd["avg"][:5000])
|
taiex = np.array(taiexpd["avg"][:5000])
|
||||||
|
|
||||||
#from statsmodels.tsa.arima_model import ARIMA as stats_arima
|
#from statsmodels.tsa.arima_model import ARIMA as stats_arima
|
||||||
from statsmodels.tsa.tsatools import lagmat
|
from statsmodels.tsa.tsatools import lagmat
|
||||||
@ -52,7 +52,7 @@ from statsmodels.tsa.tsatools import lagmat
|
|||||||
#print(lag)
|
#print(lag)
|
||||||
#print(a)
|
#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 parallel_benchmarks as bchmk
|
||||||
#from pyFTS.benchmarks import benchmarks as bchmk
|
#from pyFTS.benchmarks import benchmarks as bchmk
|
||||||
#from pyFTS.benchmarks import arima
|
#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.teste(taiex,['192.168.0.109', '192.168.0.101'])
|
||||||
|
|
||||||
#bchmk.point_sliding_window(taiex,2000,train=0.8, #models=[yu.WeightedFTS], # #
|
bchmk.point_sliding_window(taiex,2000,train=0.8, #models=[yu.WeightedFTS], # #
|
||||||
# partitioners=[Grid.GridPartitioner], #Entropy.EntropyPartitioner], # FCM.FCMPartitioner, ],
|
partitioners=[Grid.GridPartitioner], #Entropy.EntropyPartitioner], # FCM.FCMPartitioner, ],
|
||||||
# partitions= np.arange(10,200,step=5), #transformation=diff,
|
partitions= np.arange(10,200,step=5), #transformation=diff,
|
||||||
# dump=True, save=False, file="experiments/nasdaq_point_distributed.csv",
|
dump=True, save=True, file="experiments/taiex_point_distributed.csv",
|
||||||
# nodes=['192.168.1.42']) #, depends=[hofts, ifts])
|
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'])
|
#bchmk.testa(taiex,[10,20],partitioners=[Grid.GridPartitioner], nodes=['192.168.0.109', '192.168.0.101'])
|
||||||
|
|
||||||
|
7
yu.py
7
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
|
import numpy as np
|
||||||
from pyFTS.common import FuzzySet,FLR
|
from pyFTS.common import FuzzySet,FLR
|
||||||
from pyFTS import fts
|
from pyFTS import fts
|
||||||
|
Loading…
Reference in New Issue
Block a user