Correções de importações e nomenclatura devido à modularização

This commit is contained in:
Petrônio Cândido de Lima e Silva 2016-09-08 09:03:32 -03:00
parent eb27fabb4c
commit 57730cb14f
7 changed files with 36 additions and 12 deletions

View File

@ -1,10 +1,15 @@
import numpy as np import numpy as np
import pandas as pd import pandas as pd
#import matplotlib as plt import matplotlib as plt
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D 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 # Erro quadrático médio
def rmse(predictions,targets): def rmse(predictions,targets):
@ -119,7 +124,7 @@ def SelecaoKFold_MenorRMSE(original,parameters,modelo):
min_rmse_fold = 100000.0 min_rmse_fold = 100000.0
bestd = None bestd = None
fc = 0 fc = 0
diff = diferencas(original) diff = common.differential(original)
kf = KFold(len(original), n_folds=nfolds) kf = KFold(len(original), n_folds=nfolds)
for train_ix, test_ix in kf: for train_ix, test_ix in kf:
train = diff[train_ix] train = diff[train_ix]
@ -180,7 +185,7 @@ def SelecaoSimples_MenorRMSE(original,parameters,modelo):
min_rmse = 100000.0 min_rmse = 100000.0
best = None best = None
for p in parameters: for p in parameters:
sets = GridPartitionerTrimf(original,p) sets = common.GridPartitionerTrimf(original,p)
fts = modelo(str(p)+ " particoes") fts = modelo(str(p)+ " particoes")
fts.learn(original,sets) fts.learn(original,sets)
predicted = [fts.predict(xx) for xx in original] predicted = [fts.predict(xx) for xx in original]
@ -216,9 +221,9 @@ def SelecaoSimples_MenorRMSE(original,parameters,modelo):
min_rmse = 100000.0 min_rmse = 100000.0
bestd = None bestd = None
for p in parameters: for p in parameters:
sets = GridPartitionerTrimf(diferencas(original),p) sets = common.GridPartitionerTrimf(common.differential(original),p)
fts = modelo(str(p)+ " particoes") 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 = [fts.predictDiff(original, xx) for xx in range(1,len(original))]
predicted.insert(0,original[0]) predicted.insert(0,original[0])
ax2.plot(predicted,label=fts.name) ax2.plot(predicted,label=fts.name)
@ -367,7 +372,7 @@ def HOSelecaoSimples_MenorRMSE(original,parameters,orders):
for p in parameters: for p in parameters:
oc = 0 oc = 0
for o in orders: 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 = HighOrderFTS(o,"k = " + str(p)+ " w = " + str(o))
fts.learn(original,sets) fts.learn(original,sets)
predicted = [fts.predictDiff(original, xx) for xx in range(o,len(original))] predicted = [fts.predictDiff(original, xx) for xx in range(o,len(original))]

View File

@ -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): def trimf(x,parameters):
if(x < parameters[0]): if(x < parameters[0]):
return 0 return 0

2
fts.py
View File

@ -1,3 +1,5 @@
from pyFTS import *
class FTS: class FTS:
def __init__(self,order,name): def __init__(self,order,name):
self.sets = {} self.sets = {}

View File

@ -1,4 +1,6 @@
class HighOrderFTS(FTS): from pyFTS import *
class HighOrderFTS(fts.FTS):
def __init__(self,order,name): def __init__(self,order,name):
super(HighOrderFTS, self).__init__(order,name) super(HighOrderFTS, self).__init__(order,name)

View File

@ -1,3 +1,5 @@
from pyFTS import *
class ImprovedWeightedFLRG: class ImprovedWeightedFLRG:
def __init__(self,premiss): def __init__(self,premiss):
self.premiss = premiss self.premiss = premiss
@ -24,7 +26,7 @@ class ImprovedWeightedFLRG:
return tmp + tmp2 return tmp + tmp2
class ImprovedWeightedFTS(FTS): class ImprovedWeightedFTS(fts.FTS):
def __init__(self,name): def __init__(self,name):
super(ImprovedWeightedFTS, self).__init__(1,name) super(ImprovedWeightedFTS, self).__init__(1,name)

View File

@ -1,3 +1,5 @@
from pyFTS import *
class ExponentialyWeightedFLRG: class ExponentialyWeightedFLRG:
def __init__(self,premiss,c): def __init__(self,premiss,c):
self.premiss = premiss self.premiss = premiss
@ -27,7 +29,7 @@ class ExponentialyWeightedFLRG:
cc = cc + 1 cc = cc + 1
return tmp + tmp2 return tmp + tmp2
class ExponentialyWeightedFTS(FTS): class ExponentialyWeightedFTS(fts.FTS):
def __init__(self,name): def __init__(self,name):
super(ExponentialyWeightedFTS, self).__init__(1,name) super(ExponentialyWeightedFTS, self).__init__(1,name)

6
yu.py
View File

@ -1,4 +1,6 @@
class WeightedFLRG(FTS): from pyFTS import *
class WeightedFLRG(fts.FTS):
def __init__(self,premiss): def __init__(self,premiss):
self.premiss = premiss self.premiss = premiss
self.consequent = [] self.consequent = []
@ -25,7 +27,7 @@ class WeightedFLRG(FTS):
return tmp + tmp2 return tmp + tmp2
class WeightedFTS(FTS): class WeightedFTS(fts.FTS):
def __init__(self,name): def __init__(self,name):
super(WeightedFTS, self).__init__(1,name) super(WeightedFTS, self).__init__(1,name)