Padronização dos nomes dos atributos das FLRGs

This commit is contained in:
Petrônio Cândido de Lima e Silva 2016-10-18 09:50:27 -02:00
parent 7200053651
commit 82c2e56f4d
6 changed files with 44 additions and 37 deletions

View File

@ -3,6 +3,7 @@ import pandas as pd
import matplotlib as plt
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from sklearn.cross_validation import KFold
from pyFTS import common
@ -76,7 +77,7 @@ def SelecaoKFold_MenorRMSE(original,parameters,modelo):
errors_fold = []
pc = 0 #Parameter count
for p in parameters:
sets = GridPartitionerTrimf(train,p)
sets = common.GridPartitionerTrimf(train,p)
fts = modelo(str(p)+ " particoes")
fts.learn(train,sets)
predicted = [fts.predict(xx) for xx in test]
@ -306,6 +307,8 @@ def compareModelsTable(original,models_fo,models_ho):
return sup + header + body + "\\end{tabular}"
from pyFTS import hwang
def HOSelecaoSimples_MenorRMSE(original,parameters,orders):
ret = []
errors = np.array([[0 for k in range(len(parameters))] for kk in range(len(orders))])
@ -326,8 +329,8 @@ def HOSelecaoSimples_MenorRMSE(original,parameters,orders):
for p in parameters:
oc = 0
for o in orders:
sets = GridPartitionerTrimf(original,p)
fts = HighOrderFTS(o,"k = " + str(p)+ " w = " + str(o))
sets = common.GridPartitionerTrimf(original,p)
fts = hwang.HighOrderFTS(o,"k = " + str(p)+ " w = " + str(o))
fts.learn(original,sets)
predicted = [fts.predict(original, xx) for xx in range(o,len(original))]
error = rmse(np.array(predicted),np.array(original[o:]))
@ -373,7 +376,7 @@ def HOSelecaoSimples_MenorRMSE(original,parameters,orders):
oc = 0
for o in orders:
sets = common.GridPartitionerTrimf(common.differential(original),p)
fts = HighOrderFTS(o,"k = " + str(p)+ " w = " + str(o))
fts = hwang.HighOrderFTS(o,"k = " + str(p)+ " w = " + str(o))
fts.learn(original,sets)
predicted = [fts.predictDiff(original, xx) for xx in range(o,len(original))]
error = rmse(np.array(predicted),np.array(original[o:]))

14
chen.py
View File

@ -1,17 +1,17 @@
from pyFTS import *
class ConventionalFLRG:
def __init__(self,premiss):
self.premiss = premiss
self.consequent = set()
def __init__(self,LHS):
self.LHS = LHS
self.RHS = set()
def append(self,c):
self.consequent.add(c)
self.RHS.add(c)
def __str__(self):
tmp = self.premiss + " -> "
tmp = self.LHS + " -> "
tmp2 = ""
for c in self.consequent:
for c in self.RHS:
if len(tmp2) > 0:
tmp2 = tmp2 + ","
tmp2 = tmp2 + c
@ -34,7 +34,7 @@ class ConventionalFTS(fts.FTS):
count = 0.0
denom = 0.0
for s in flrg.consequent:
for s in flrg.RHS:
denom = denom + self.sets[s].centroid
count = count + 1.0

View File

@ -1,3 +1,4 @@
import numpy as np
from pyFTS import *
class HighOrderFTS(fts.FTS):
@ -33,4 +34,4 @@ class HighOrderFTS(fts.FTS):
return self.defuzzy(data,t)
def predictDiff(self,data,t):
return data[t] + self.defuzzy(diferencas(data),t)
return data[t] + self.defuzzy(common.differential(data),t)

View File

@ -1,28 +1,29 @@
import numpy as np
from pyFTS import *
class ImprovedWeightedFLRG:
def __init__(self,premiss):
self.premiss = premiss
self.consequent = {}
def __init__(self,LHS):
self.LHS = LHS
self.RHS = {}
self.count = 0.0
def append(self,c):
if c not in self.consequent:
self.consequent[c] = 1.0
if c not in self.RHS:
self.RHS[c] = 1.0
else:
self.consequent[c] = self.consequent[c] + 1.0
self.RHS[c] = self.RHS[c] + 1.0
self.count = self.count + 1.0
def weights(self):
return np.array([ self.consequent[c]/self.count for c in self.consequent.keys() ])
return np.array([ self.RHS[c]/self.count for c in self.RHS.keys() ])
def __str__(self):
tmp = self.premiss + " -> "
tmp = self.LHS + " -> "
tmp2 = ""
for c in self.consequent.keys():
for c in self.RHS.keys():
if len(tmp2) > 0:
tmp2 = tmp2 + ","
tmp2 = tmp2 + c + "(" + str(round(self.consequent[c]/self.count,3)) + ")"
tmp2 = tmp2 + c + "(" + str(round(self.RHS[c]/self.count,3)) + ")"
return tmp + tmp2
@ -35,7 +36,7 @@ class ImprovedWeightedFTS(fts.FTS):
if actual["fuzzyset"] not in self.flrgs:
return self.sets[actual["fuzzyset"]].centroid
flrg = self.flrgs[actual["fuzzyset"]]
mi = np.array([self.sets[s].centroid for s in flrg.consequent.keys()])
mi = np.array([self.sets[s].centroid for s in flrg.RHS.keys()])
return mi.dot( flrg.weights() )
def learn(self, data, sets):

View File

@ -1,14 +1,15 @@
import numpy as np
from pyFTS import *
class ExponentialyWeightedFLRG:
def __init__(self,premiss,c):
self.premiss = premiss
self.consequent = []
def __init__(self,LHS,c):
self.LHS = LHS
self.RHS = []
self.count = 0.0
self.c = c
def append(self,c):
self.consequent.append(c)
self.RHS.append(c)
self.count = self.count + 1.0
def weights(self):
@ -17,12 +18,12 @@ class ExponentialyWeightedFLRG:
return np.array([ k/tot for k in wei ])
def __str__(self):
tmp = self.premiss + " -> "
tmp = self.LHS + " -> "
tmp2 = ""
cc = 0
wei = [ self.c**k for k in np.arange(0.0,self.count,1.0)]
tot = sum( wei )
for c in self.consequent:
for c in self.RHS:
if len(tmp2) > 0:
tmp2 = tmp2 + ","
tmp2 = tmp2 + c + "(" + str(wei[cc]/tot) + ")"
@ -42,7 +43,7 @@ class ExponentialyWeightedFTS(fts.FTS):
flrg = self.flrgs[actual["fuzzyset"]]
mi = np.array([self.sets[s].centroid for s in flrg.consequent])
mi = np.array([self.sets[s].centroid for s in flrg.RHS])
return mi.dot( flrg.weights() )

15
yu.py
View File

@ -1,13 +1,14 @@
import numpy as np
from pyFTS import *
class WeightedFLRG(fts.FTS):
def __init__(self,premiss):
self.premiss = premiss
self.consequent = []
def __init__(self,LHS):
self.LHS = LHS
self.RHS = []
self.count = 1.0
def append(self,c):
self.consequent.append(c)
self.RHS.append(c)
self.count = self.count + 1.0
def weights(self):
@ -15,11 +16,11 @@ class WeightedFLRG(fts.FTS):
return np.array([ k/tot for k in np.arange(1.0,self.count,1.0) ])
def __str__(self):
tmp = self.premiss + " -> "
tmp = self.LHS + " -> "
tmp2 = ""
cc = 1.0
tot = sum( np.arange(1.0,self.count,1.0) )
for c in self.consequent:
for c in self.RHS:
if len(tmp2) > 0:
tmp2 = tmp2 + ","
tmp2 = tmp2 + c + "(" + str(round(cc/tot,3)) + ")"
@ -40,7 +41,7 @@ class WeightedFTS(fts.FTS):
flrg = self.flrgs[actual["fuzzyset"]]
mi = np.array([self.sets[s].centroid for s in flrg.consequent])
mi = np.array([self.sets[s].centroid for s in flrg.RHS])
return mi.dot( flrg.weights() )