Padronização dos nomes dos atributos das FLRGs
This commit is contained in:
parent
7200053651
commit
82c2e56f4d
@ -3,6 +3,7 @@ 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 sklearn.cross_validation import KFold
|
||||||
|
|
||||||
from pyFTS import common
|
from pyFTS import common
|
||||||
|
|
||||||
@ -76,7 +77,7 @@ def SelecaoKFold_MenorRMSE(original,parameters,modelo):
|
|||||||
errors_fold = []
|
errors_fold = []
|
||||||
pc = 0 #Parameter count
|
pc = 0 #Parameter count
|
||||||
for p in parameters:
|
for p in parameters:
|
||||||
sets = GridPartitionerTrimf(train,p)
|
sets = common.GridPartitionerTrimf(train,p)
|
||||||
fts = modelo(str(p)+ " particoes")
|
fts = modelo(str(p)+ " particoes")
|
||||||
fts.learn(train,sets)
|
fts.learn(train,sets)
|
||||||
predicted = [fts.predict(xx) for xx in test]
|
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}"
|
return sup + header + body + "\\end{tabular}"
|
||||||
|
|
||||||
|
from pyFTS import hwang
|
||||||
|
|
||||||
def HOSelecaoSimples_MenorRMSE(original,parameters,orders):
|
def HOSelecaoSimples_MenorRMSE(original,parameters,orders):
|
||||||
ret = []
|
ret = []
|
||||||
errors = np.array([[0 for k in range(len(parameters))] for kk in range(len(orders))])
|
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:
|
for p in parameters:
|
||||||
oc = 0
|
oc = 0
|
||||||
for o in orders:
|
for o in orders:
|
||||||
sets = GridPartitionerTrimf(original,p)
|
sets = common.GridPartitionerTrimf(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)
|
fts.learn(original,sets)
|
||||||
predicted = [fts.predict(original, xx) for xx in range(o,len(original))]
|
predicted = [fts.predict(original, xx) for xx in range(o,len(original))]
|
||||||
error = rmse(np.array(predicted),np.array(original[o:]))
|
error = rmse(np.array(predicted),np.array(original[o:]))
|
||||||
@ -373,7 +376,7 @@ def HOSelecaoSimples_MenorRMSE(original,parameters,orders):
|
|||||||
oc = 0
|
oc = 0
|
||||||
for o in orders:
|
for o in orders:
|
||||||
sets = common.GridPartitionerTrimf(common.differential(original),p)
|
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)
|
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))]
|
||||||
error = rmse(np.array(predicted),np.array(original[o:]))
|
error = rmse(np.array(predicted),np.array(original[o:]))
|
||||||
|
14
chen.py
14
chen.py
@ -1,17 +1,17 @@
|
|||||||
from pyFTS import *
|
from pyFTS import *
|
||||||
|
|
||||||
class ConventionalFLRG:
|
class ConventionalFLRG:
|
||||||
def __init__(self,premiss):
|
def __init__(self,LHS):
|
||||||
self.premiss = premiss
|
self.LHS = LHS
|
||||||
self.consequent = set()
|
self.RHS = set()
|
||||||
|
|
||||||
def append(self,c):
|
def append(self,c):
|
||||||
self.consequent.add(c)
|
self.RHS.add(c)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
tmp = self.premiss + " -> "
|
tmp = self.LHS + " -> "
|
||||||
tmp2 = ""
|
tmp2 = ""
|
||||||
for c in self.consequent:
|
for c in self.RHS:
|
||||||
if len(tmp2) > 0:
|
if len(tmp2) > 0:
|
||||||
tmp2 = tmp2 + ","
|
tmp2 = tmp2 + ","
|
||||||
tmp2 = tmp2 + c
|
tmp2 = tmp2 + c
|
||||||
@ -34,7 +34,7 @@ class ConventionalFTS(fts.FTS):
|
|||||||
count = 0.0
|
count = 0.0
|
||||||
denom = 0.0
|
denom = 0.0
|
||||||
|
|
||||||
for s in flrg.consequent:
|
for s in flrg.RHS:
|
||||||
denom = denom + self.sets[s].centroid
|
denom = denom + self.sets[s].centroid
|
||||||
count = count + 1.0
|
count = count + 1.0
|
||||||
|
|
||||||
|
3
hwang.py
3
hwang.py
@ -1,3 +1,4 @@
|
|||||||
|
import numpy as np
|
||||||
from pyFTS import *
|
from pyFTS import *
|
||||||
|
|
||||||
class HighOrderFTS(fts.FTS):
|
class HighOrderFTS(fts.FTS):
|
||||||
@ -33,4 +34,4 @@ class HighOrderFTS(fts.FTS):
|
|||||||
return self.defuzzy(data,t)
|
return self.defuzzy(data,t)
|
||||||
|
|
||||||
def predictDiff(self,data,t):
|
def predictDiff(self,data,t):
|
||||||
return data[t] + self.defuzzy(diferencas(data),t)
|
return data[t] + self.defuzzy(common.differential(data),t)
|
||||||
|
@ -1,28 +1,29 @@
|
|||||||
|
import numpy as np
|
||||||
from pyFTS import *
|
from pyFTS import *
|
||||||
|
|
||||||
class ImprovedWeightedFLRG:
|
class ImprovedWeightedFLRG:
|
||||||
def __init__(self,premiss):
|
def __init__(self,LHS):
|
||||||
self.premiss = premiss
|
self.LHS = LHS
|
||||||
self.consequent = {}
|
self.RHS = {}
|
||||||
self.count = 0.0
|
self.count = 0.0
|
||||||
|
|
||||||
def append(self,c):
|
def append(self,c):
|
||||||
if c not in self.consequent:
|
if c not in self.RHS:
|
||||||
self.consequent[c] = 1.0
|
self.RHS[c] = 1.0
|
||||||
else:
|
else:
|
||||||
self.consequent[c] = self.consequent[c] + 1.0
|
self.RHS[c] = self.RHS[c] + 1.0
|
||||||
self.count = self.count + 1.0
|
self.count = self.count + 1.0
|
||||||
|
|
||||||
def weights(self):
|
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):
|
def __str__(self):
|
||||||
tmp = self.premiss + " -> "
|
tmp = self.LHS + " -> "
|
||||||
tmp2 = ""
|
tmp2 = ""
|
||||||
for c in self.consequent.keys():
|
for c in self.RHS.keys():
|
||||||
if len(tmp2) > 0:
|
if len(tmp2) > 0:
|
||||||
tmp2 = tmp2 + ","
|
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
|
return tmp + tmp2
|
||||||
|
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ class ImprovedWeightedFTS(fts.FTS):
|
|||||||
if actual["fuzzyset"] not in self.flrgs:
|
if actual["fuzzyset"] not in self.flrgs:
|
||||||
return self.sets[actual["fuzzyset"]].centroid
|
return self.sets[actual["fuzzyset"]].centroid
|
||||||
flrg = self.flrgs[actual["fuzzyset"]]
|
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() )
|
return mi.dot( flrg.weights() )
|
||||||
|
|
||||||
def learn(self, data, sets):
|
def learn(self, data, sets):
|
||||||
|
15
sadaei.py
15
sadaei.py
@ -1,14 +1,15 @@
|
|||||||
|
import numpy as np
|
||||||
from pyFTS import *
|
from pyFTS import *
|
||||||
|
|
||||||
class ExponentialyWeightedFLRG:
|
class ExponentialyWeightedFLRG:
|
||||||
def __init__(self,premiss,c):
|
def __init__(self,LHS,c):
|
||||||
self.premiss = premiss
|
self.LHS = LHS
|
||||||
self.consequent = []
|
self.RHS = []
|
||||||
self.count = 0.0
|
self.count = 0.0
|
||||||
self.c = c
|
self.c = c
|
||||||
|
|
||||||
def append(self,c):
|
def append(self,c):
|
||||||
self.consequent.append(c)
|
self.RHS.append(c)
|
||||||
self.count = self.count + 1.0
|
self.count = self.count + 1.0
|
||||||
|
|
||||||
def weights(self):
|
def weights(self):
|
||||||
@ -17,12 +18,12 @@ class ExponentialyWeightedFLRG:
|
|||||||
return np.array([ k/tot for k in wei ])
|
return np.array([ k/tot for k in wei ])
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
tmp = self.premiss + " -> "
|
tmp = self.LHS + " -> "
|
||||||
tmp2 = ""
|
tmp2 = ""
|
||||||
cc = 0
|
cc = 0
|
||||||
wei = [ self.c**k for k in np.arange(0.0,self.count,1.0)]
|
wei = [ self.c**k for k in np.arange(0.0,self.count,1.0)]
|
||||||
tot = sum( wei )
|
tot = sum( wei )
|
||||||
for c in self.consequent:
|
for c in self.RHS:
|
||||||
if len(tmp2) > 0:
|
if len(tmp2) > 0:
|
||||||
tmp2 = tmp2 + ","
|
tmp2 = tmp2 + ","
|
||||||
tmp2 = tmp2 + c + "(" + str(wei[cc]/tot) + ")"
|
tmp2 = tmp2 + c + "(" + str(wei[cc]/tot) + ")"
|
||||||
@ -42,7 +43,7 @@ class ExponentialyWeightedFTS(fts.FTS):
|
|||||||
|
|
||||||
flrg = self.flrgs[actual["fuzzyset"]]
|
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() )
|
return mi.dot( flrg.weights() )
|
||||||
|
|
||||||
|
15
yu.py
15
yu.py
@ -1,13 +1,14 @@
|
|||||||
|
import numpy as np
|
||||||
from pyFTS import *
|
from pyFTS import *
|
||||||
|
|
||||||
class WeightedFLRG(fts.FTS):
|
class WeightedFLRG(fts.FTS):
|
||||||
def __init__(self,premiss):
|
def __init__(self,LHS):
|
||||||
self.premiss = premiss
|
self.LHS = LHS
|
||||||
self.consequent = []
|
self.RHS = []
|
||||||
self.count = 1.0
|
self.count = 1.0
|
||||||
|
|
||||||
def append(self,c):
|
def append(self,c):
|
||||||
self.consequent.append(c)
|
self.RHS.append(c)
|
||||||
self.count = self.count + 1.0
|
self.count = self.count + 1.0
|
||||||
|
|
||||||
def weights(self):
|
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) ])
|
return np.array([ k/tot for k in np.arange(1.0,self.count,1.0) ])
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
tmp = self.premiss + " -> "
|
tmp = self.LHS + " -> "
|
||||||
tmp2 = ""
|
tmp2 = ""
|
||||||
cc = 1.0
|
cc = 1.0
|
||||||
tot = sum( np.arange(1.0,self.count,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:
|
if len(tmp2) > 0:
|
||||||
tmp2 = tmp2 + ","
|
tmp2 = tmp2 + ","
|
||||||
tmp2 = tmp2 + c + "(" + str(round(cc/tot,3)) + ")"
|
tmp2 = tmp2 + c + "(" + str(round(cc/tot,3)) + ")"
|
||||||
@ -40,7 +41,7 @@ class WeightedFTS(fts.FTS):
|
|||||||
|
|
||||||
flrg = self.flrgs[actual["fuzzyset"]]
|
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() )
|
return mi.dot( flrg.weights() )
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user