diff --git a/benchmarks.py b/benchmarks.py index 1ca0f34..5a3df46 100644 --- a/benchmarks.py +++ b/benchmarks.py @@ -1,10 +1,15 @@ import numpy as np import pandas as pd -#import matplotlib as plt +import matplotlib as plt import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D -from pyFTS import * +from pyFTS import common + +def Teste(par): + x = np.arange(1,par) + y = [ yy**yy for yyy in x] + plt.plot(x,y) # Erro quadrático médio def rmse(predictions,targets): @@ -119,7 +124,7 @@ def SelecaoKFold_MenorRMSE(original,parameters,modelo): min_rmse_fold = 100000.0 bestd = None fc = 0 - diff = diferencas(original) + diff = common.differential(original) kf = KFold(len(original), n_folds=nfolds) for train_ix, test_ix in kf: train = diff[train_ix] @@ -180,7 +185,7 @@ def SelecaoSimples_MenorRMSE(original,parameters,modelo): min_rmse = 100000.0 best = None for p in parameters: - sets = GridPartitionerTrimf(original,p) + sets = common.GridPartitionerTrimf(original,p) fts = modelo(str(p)+ " particoes") fts.learn(original,sets) predicted = [fts.predict(xx) for xx in original] @@ -216,9 +221,9 @@ def SelecaoSimples_MenorRMSE(original,parameters,modelo): min_rmse = 100000.0 bestd = None for p in parameters: - sets = GridPartitionerTrimf(diferencas(original),p) + sets = common.GridPartitionerTrimf(common.differential(original),p) fts = modelo(str(p)+ " particoes") - fts.learn(diferencas(original),sets) + fts.learn(common.differential(original),sets) predicted = [fts.predictDiff(original, xx) for xx in range(1,len(original))] predicted.insert(0,original[0]) ax2.plot(predicted,label=fts.name) @@ -367,7 +372,7 @@ def HOSelecaoSimples_MenorRMSE(original,parameters,orders): for p in parameters: oc = 0 for o in orders: - sets = GridPartitionerTrimf(diferencas(original),p) + sets = common.GridPartitionerTrimf(common.differential(original),p) fts = HighOrderFTS(o,"k = " + str(p)+ " w = " + str(o)) fts.learn(original,sets) predicted = [fts.predictDiff(original, xx) for xx in range(o,len(original))] diff --git a/common.py b/common.py index 1e68b41..b99703b 100644 --- a/common.py +++ b/common.py @@ -1,3 +1,12 @@ +import numpy as np +from pyFTS import * + +def differential(original): + n = len(original) + diff = [ original[t-1]-original[t] for t in np.arange(1,n) ] + diff.insert(0,0) + return np.array(diff) + def trimf(x,parameters): if(x < parameters[0]): return 0 diff --git a/fts.py b/fts.py index 91cb50e..c4cd802 100644 --- a/fts.py +++ b/fts.py @@ -1,3 +1,5 @@ +from pyFTS import * + class FTS: def __init__(self,order,name): self.sets = {} diff --git a/hwang.py b/hwang.py index 8ba552a..7d5e7e5 100644 --- a/hwang.py +++ b/hwang.py @@ -1,4 +1,6 @@ -class HighOrderFTS(FTS): +from pyFTS import * + +class HighOrderFTS(fts.FTS): def __init__(self,order,name): super(HighOrderFTS, self).__init__(order,name) diff --git a/ismailefendi.py b/ismailefendi.py index e425725..1c88a85 100644 --- a/ismailefendi.py +++ b/ismailefendi.py @@ -1,3 +1,5 @@ +from pyFTS import * + class ImprovedWeightedFLRG: def __init__(self,premiss): self.premiss = premiss @@ -24,7 +26,7 @@ class ImprovedWeightedFLRG: return tmp + tmp2 -class ImprovedWeightedFTS(FTS): +class ImprovedWeightedFTS(fts.FTS): def __init__(self,name): super(ImprovedWeightedFTS, self).__init__(1,name) diff --git a/sadaei.py b/sadaei.py index a7f0223..664964e 100644 --- a/sadaei.py +++ b/sadaei.py @@ -1,3 +1,5 @@ +from pyFTS import * + class ExponentialyWeightedFLRG: def __init__(self,premiss,c): self.premiss = premiss @@ -27,7 +29,7 @@ class ExponentialyWeightedFLRG: cc = cc + 1 return tmp + tmp2 -class ExponentialyWeightedFTS(FTS): +class ExponentialyWeightedFTS(fts.FTS): def __init__(self,name): super(ExponentialyWeightedFTS, self).__init__(1,name) diff --git a/yu.py b/yu.py index 8cbee58..845b117 100644 --- a/yu.py +++ b/yu.py @@ -1,4 +1,6 @@ -class WeightedFLRG(FTS): +from pyFTS import * + +class WeightedFLRG(fts.FTS): def __init__(self,premiss): self.premiss = premiss self.consequent = [] @@ -25,7 +27,7 @@ class WeightedFLRG(FTS): return tmp + tmp2 -class WeightedFTS(FTS): +class WeightedFTS(fts.FTS): def __init__(self,name): super(WeightedFTS, self).__init__(1,name)