Refatoração dos códigos para padronizar com a rfts
This commit is contained in:
parent
587fce885e
commit
30ccb6a88f
@ -189,7 +189,10 @@ def SelecaoSimples_MenorRMSE(original,parameters,modelo):
|
|||||||
sets = partitioner.GridPartitionerTrimf(original,p)
|
sets = partitioner.GridPartitionerTrimf(original,p)
|
||||||
fts = modelo(str(p)+ " particoes")
|
fts = modelo(str(p)+ " particoes")
|
||||||
fts.train(original,sets)
|
fts.train(original,sets)
|
||||||
forecasted = [fts.forecast(xx) for xx in original]
|
#print(original)
|
||||||
|
forecasted = fts.forecast(original)
|
||||||
|
forecasted.insert(0,original[0])
|
||||||
|
#print(forecasted)
|
||||||
ax0.plot(forecasted,label=fts.name)
|
ax0.plot(forecasted,label=fts.name)
|
||||||
error = rmse(np.array(forecasted),np.array(original))
|
error = rmse(np.array(forecasted),np.array(original))
|
||||||
print(p,error)
|
print(p,error)
|
||||||
@ -226,8 +229,8 @@ def SelecaoSimples_MenorRMSE(original,parameters,modelo):
|
|||||||
sets = partitioner.GridPartitionerTrimf(difffts,p)
|
sets = partitioner.GridPartitionerTrimf(difffts,p)
|
||||||
fts = modelo(str(p)+ " particoes")
|
fts = modelo(str(p)+ " particoes")
|
||||||
fts.train(difffts,sets)
|
fts.train(difffts,sets)
|
||||||
forecasted = [fts.forecast(xx) for xx in difffts]
|
forecasted = fts.forecast(difffts)
|
||||||
#forecasted.insert(0,difffts[0])
|
forecasted.insert(0,difffts[0])
|
||||||
ax2.plot(forecasted,label=fts.name)
|
ax2.plot(forecasted,label=fts.name)
|
||||||
error = rmse(np.array(forecasted),np.array(difffts))
|
error = rmse(np.array(forecasted),np.array(difffts))
|
||||||
print(p,error)
|
print(p,error)
|
||||||
|
38
chen.py
38
chen.py
@ -24,14 +24,14 @@ class ConventionalFTS(fts.FTS):
|
|||||||
super(ConventionalFTS, self).__init__(1,name)
|
super(ConventionalFTS, self).__init__(1,name)
|
||||||
self.flrgs = {}
|
self.flrgs = {}
|
||||||
|
|
||||||
def generateFLRG(self, flrs):
|
def generateFLRG(self, flrs):
|
||||||
flrgs = {}
|
flrgs = {}
|
||||||
for flr in flrs:
|
for flr in flrs:
|
||||||
if flr.LHS in flrgs:
|
if flr.LHS.name in flrgs:
|
||||||
flrgs[flr.LHS].append(flr.RHS)
|
flrgs[flr.LHS.name].append(flr.RHS)
|
||||||
else:
|
else:
|
||||||
flrgs[flr.LHS] = ConventionalFLRG(flr.LHS);
|
flrgs[flr.LHS.name] = ConventionalFLRG(flr.LHS);
|
||||||
flrgs[flr.LHS].append(flr.RHS)
|
flrgs[flr.LHS.name].append(flr.RHS)
|
||||||
return (flrgs)
|
return (flrgs)
|
||||||
|
|
||||||
def train(self, data, sets):
|
def train(self, data, sets):
|
||||||
@ -42,23 +42,29 @@ class ConventionalFTS(fts.FTS):
|
|||||||
|
|
||||||
def forecast(self,data):
|
def forecast(self,data):
|
||||||
|
|
||||||
mv = common.fuzzyInstance(data, self.sets)
|
l = 1
|
||||||
|
|
||||||
actual = self.sets[ np.argwhere( mv == max(mv) )[0,0] ]
|
ndata = np.array(data)
|
||||||
|
|
||||||
if actual.name not in self.flrgs:
|
l = len(ndata)
|
||||||
return actual.centroid
|
|
||||||
|
|
||||||
flrg = self.flrgs[actual.name]
|
ret = []
|
||||||
|
|
||||||
count = 0.0
|
for k in np.arange(1,l):
|
||||||
denom = 0.0
|
|
||||||
|
|
||||||
for s in flrg.RHS:
|
mv = common.fuzzyInstance(ndata[k], self.sets)
|
||||||
denom = denom + self.sets[s].centroid
|
|
||||||
count = count + 1.0
|
|
||||||
|
|
||||||
return denom/count
|
actual = self.sets[ np.argwhere( mv == max(mv) )[0,0] ]
|
||||||
|
|
||||||
|
if actual.name not in self.flrgs:
|
||||||
|
ret.append(actual.centroid)
|
||||||
|
else:
|
||||||
|
flrg = self.flrgs[actual.name]
|
||||||
|
mp = self.getMidpoints(flrg)
|
||||||
|
|
||||||
|
ret.append(sum(mp)/len(mp))
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
5
fts.py
5
fts.py
@ -1,3 +1,4 @@
|
|||||||
|
import numpy as np
|
||||||
from pyFTS import *
|
from pyFTS import *
|
||||||
|
|
||||||
class FTS:
|
class FTS:
|
||||||
@ -24,6 +25,10 @@ class FTS:
|
|||||||
def train(self, data, sets):
|
def train(self, data, sets):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def getMidpoints(self,flrg):
|
||||||
|
ret = np.array([s.centroid for s in flrg.RHS])
|
||||||
|
return ret
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
tmp = self.name + ":\n"
|
tmp = self.name + ":\n"
|
||||||
for r in self.flrgs.keys():
|
for r in self.flrgs.keys():
|
||||||
|
@ -48,14 +48,26 @@ class ImprovedWeightedFTS(fts.FTS):
|
|||||||
self.flrgs = self.generateFLRG(flrs)
|
self.flrgs = self.generateFLRG(flrs)
|
||||||
|
|
||||||
def forecast(self,data):
|
def forecast(self,data):
|
||||||
mv = common.fuzzyInstance(data, self.sets)
|
l = 1
|
||||||
|
|
||||||
actual = self.sets[ np.argwhere( mv == max(mv) )[0,0] ]
|
ndata = np.array(data)
|
||||||
|
|
||||||
if actual.name not in self.flrgs:
|
l = len(ndata)
|
||||||
return actual.centroid
|
|
||||||
|
|
||||||
flrg = self.flrgs[actual.name]
|
ret = []
|
||||||
|
|
||||||
mi = np.array([self.sets[s].centroid for s in flrg.RHS.keys()])
|
for k in np.arange(1,l):
|
||||||
return mi.dot( flrg.weights() )
|
|
||||||
|
mv = common.fuzzyInstance(ndata[k], self.sets)
|
||||||
|
|
||||||
|
actual = self.sets[ np.argwhere( mv == max(mv) )[0,0] ]
|
||||||
|
|
||||||
|
if actual.name not in self.flrgs:
|
||||||
|
ret.append(actual.centroid)
|
||||||
|
else:
|
||||||
|
flrg = self.flrgs[actual.name]
|
||||||
|
mp = self.getMidpoints(flrg)
|
||||||
|
|
||||||
|
ret.append( mi.dot( flrg.weights() ))
|
||||||
|
|
||||||
|
return ret
|
||||||
|
25
sadaei.py
25
sadaei.py
@ -53,16 +53,27 @@ class ExponentialyWeightedFTS(fts.FTS):
|
|||||||
self.flrgs = self.generateFLRG(flrs,c)
|
self.flrgs = self.generateFLRG(flrs,c)
|
||||||
|
|
||||||
def forecast(self,data):
|
def forecast(self,data):
|
||||||
mv = common.fuzzyInstance(data, self.sets)
|
l = 1
|
||||||
|
|
||||||
actual = self.sets[ np.argwhere( mv == max(mv) )[0,0] ]
|
ndata = np.array(data)
|
||||||
|
|
||||||
if actual.name not in self.flrgs:
|
l = len(ndata)
|
||||||
return actual.centroid
|
|
||||||
|
|
||||||
flrg = self.flrgs[actual.name]
|
ret = []
|
||||||
|
|
||||||
mi = np.array([self.sets[s].centroid for s in flrg.RHS])
|
for k in np.arange(1,l):
|
||||||
|
|
||||||
return mi.dot( flrg.weights() )
|
mv = common.fuzzyInstance(ndata[k], self.sets)
|
||||||
|
|
||||||
|
actual = self.sets[ np.argwhere( mv == max(mv) )[0,0] ]
|
||||||
|
|
||||||
|
if actual.name not in self.flrgs:
|
||||||
|
ret.append(actual.centroid)
|
||||||
|
else:
|
||||||
|
flrg = self.flrgs[actual.name]
|
||||||
|
mp = self.getMidpoints(flrg)
|
||||||
|
|
||||||
|
ret.append( mi.dot( flrg.weights() ))
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
|
31
yu.py
31
yu.py
@ -35,11 +35,11 @@ class WeightedFTS(fts.FTS):
|
|||||||
def generateFLRG(self, flrs):
|
def generateFLRG(self, flrs):
|
||||||
flrgs = {}
|
flrgs = {}
|
||||||
for flr in flrs:
|
for flr in flrs:
|
||||||
if flr.LHS in flrgs:
|
if flr.LHS.name in flrgs:
|
||||||
flrgs[flr.LHS].append(flr.RHS)
|
flrgs[flr.LHS.name].append(flr.RHS)
|
||||||
else:
|
else:
|
||||||
flrgs[flr.LHS] = WeightedFLRG(flr.LHS);
|
flrgs[flr.LHS.name] = WeightedFLRG(flr.LHS);
|
||||||
flrgs[flr.LHS].append(flr.RHS)
|
flrgs[flr.LHS.name].append(flr.RHS)
|
||||||
return (flrgs)
|
return (flrgs)
|
||||||
|
|
||||||
def train(self, data, sets):
|
def train(self, data, sets):
|
||||||
@ -49,17 +49,26 @@ class WeightedFTS(fts.FTS):
|
|||||||
self.flrgs = self.generateFLRG(flrs)
|
self.flrgs = self.generateFLRG(flrs)
|
||||||
|
|
||||||
def forecast(self,data):
|
def forecast(self,data):
|
||||||
|
l = 1
|
||||||
|
|
||||||
mv = common.fuzzyInstance(data, self.sets)
|
ndata = np.array(data)
|
||||||
|
|
||||||
actual = self.sets[ np.argwhere( mv == max(mv) )[0,0] ]
|
l = len(ndata)
|
||||||
|
|
||||||
if actual.name not in self.flrgs:
|
ret = []
|
||||||
return actual.centroid
|
|
||||||
|
|
||||||
flrg = self.flrgs[actual.name]
|
for k in np.arange(1,l):
|
||||||
|
|
||||||
mi = np.array([self.sets[s].centroid for s in flrg.RHS])
|
mv = common.fuzzyInstance(ndata[k], self.sets)
|
||||||
|
|
||||||
return mi.dot( flrg.weights() )
|
actual = self.sets[ np.argwhere( mv == max(mv) )[0,0] ]
|
||||||
|
|
||||||
|
if actual.name not in self.flrgs:
|
||||||
|
ret.append(actual.centroid)
|
||||||
|
else:
|
||||||
|
flrg = self.flrgs[actual.name]
|
||||||
|
mp = self.getMidpoints(flrg)
|
||||||
|
|
||||||
|
ret.append( mi.dot( flrg.weights() ))
|
||||||
|
|
||||||
|
return ret
|
||||||
|
Loading…
Reference in New Issue
Block a user