From 82c2e56f4dd09fb0212a9bc2d9884b802b56bcc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=C3=B4nio=20C=C3=A2ndido=20de=20Lima=20e=20Silva?= Date: Tue, 18 Oct 2016 09:50:27 -0200 Subject: [PATCH] =?UTF-8?q?Padroniza=C3=A7=C3=A3o=20dos=20nomes=20dos=20at?= =?UTF-8?q?ributos=20das=20FLRGs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchmarks.py | 11 +++++++---- chen.py | 14 +++++++------- hwang.py | 3 ++- ismailefendi.py | 23 ++++++++++++----------- sadaei.py | 15 ++++++++------- yu.py | 15 ++++++++------- 6 files changed, 44 insertions(+), 37 deletions(-) diff --git a/benchmarks.py b/benchmarks.py index 5a3df46..c406b99 100644 --- a/benchmarks.py +++ b/benchmarks.py @@ -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:])) diff --git a/chen.py b/chen.py index 768a557..2781b48 100644 --- a/chen.py +++ b/chen.py @@ -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 diff --git a/hwang.py b/hwang.py index 7d5e7e5..4ae777b 100644 --- a/hwang.py +++ b/hwang.py @@ -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) diff --git a/ismailefendi.py b/ismailefendi.py index 1c88a85..7027e37 100644 --- a/ismailefendi.py +++ b/ismailefendi.py @@ -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): diff --git a/sadaei.py b/sadaei.py index 664964e..5676978 100644 --- a/sadaei.py +++ b/sadaei.py @@ -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() ) diff --git a/yu.py b/yu.py index 845b117..47ee4b3 100644 --- a/yu.py +++ b/yu.py @@ -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() )