From 587fce885e59fa78d138e1f53c5776bcd6401039 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 17:51:59 -0200 Subject: [PATCH] =?UTF-8?q?Refatora=C3=A7=C3=A3o=20dos=20c=C3=B3digos=20pa?= =?UTF-8?q?ra=20padronizar=20com=20a=20rfts=20-=20Sadaei?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sadaei.py | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/sadaei.py b/sadaei.py index 60b4d1f..f89be11 100644 --- a/sadaei.py +++ b/sadaei.py @@ -33,36 +33,36 @@ class ExponentialyWeightedFLRG: class ExponentialyWeightedFTS(fts.FTS): def __init__(self,name): super(ExponentialyWeightedFTS, self).__init__(1,name) + this.c = 1 + + def generateFLRG(self, flrs, c): + flrgs = {} + for flr in flrs: + if flr.LHS in flrgs: + flrgs[flr.LHS].append(flr.RHS) + else: + flrgs[flr.LHS] = ExponentialyWeightedFLRG(flr.LHS, c); + flrgs[flr.LHS].append(flr.RHS) + return (flrgs) + + def train(self, data, sets, c): + this.c = c + self.sets = sets + tmpdata = common.fuzzySeries(data,sets) + flrs = common.generateRecurrentFLRs(tmpdata) + self.flrgs = self.generateFLRG(flrs,c) def forecast(self,data): + mv = common.fuzzyInstance(data, self.sets) + + actual = self.sets[ np.argwhere( mv == max(mv) )[0,0] ] - actual = self.fuzzy(data) - - if actual["fuzzyset"] not in self.flrgs: - return self.sets[actual["fuzzyset"]].centroid + if actual.name not in self.flrgs: + return actual.centroid - flrg = self.flrgs[actual["fuzzyset"]] + flrg = self.flrgs[actual.name] mi = np.array([self.sets[s].centroid for s in flrg.RHS]) return mi.dot( flrg.weights() ) - def train(self, data, sets): - last = {"fuzzyset":"", "membership":0.0} - actual = {"fuzzyset":"", "membership":0.0} - - for s in sets: - self.sets[s.name] = s - - self.flrgs = {} - count = 1 - for inst in data: - actual = self.fuzzy(inst) - - if count > self.order: - if last["fuzzyset"] not in self.flrgs: - self.flrgs[last["fuzzyset"]] = ExponentialyWeightedFLRG(last["fuzzyset"],2) - - self.flrgs[last["fuzzyset"]].append(actual["fuzzyset"]) - count = count + 1 - last = actual