Refatoração dos códigos para padronizar com a rfts - Co Yu
This commit is contained in:
parent
9ad28b07f2
commit
aa7389e228
30
chen.py
30
chen.py
@ -24,6 +24,22 @@ class ConventionalFTS(fts.FTS):
|
|||||||
super(ConventionalFTS, self).__init__(1,name)
|
super(ConventionalFTS, self).__init__(1,name)
|
||||||
self.flrgs = {}
|
self.flrgs = {}
|
||||||
|
|
||||||
|
def generateFLRG(self, flrs):
|
||||||
|
flrgs = {}
|
||||||
|
for flr in flrs:
|
||||||
|
if flr.LHS in flrgs:
|
||||||
|
flrgs[flr.LHS].append(flr.RHS)
|
||||||
|
else:
|
||||||
|
flrgs[flr.LHS] = ConventionalFLRG(flr.LHS);
|
||||||
|
flrgs[flr.LHS].append(flr.RHS)
|
||||||
|
return (flrgs)
|
||||||
|
|
||||||
|
def train(self, data, sets):
|
||||||
|
self.sets = sets
|
||||||
|
tmpdata = common.fuzzySeries(data,sets)
|
||||||
|
flrs = common.generateNonRecurrentFLRs(tmpdata)
|
||||||
|
self.flrgs = self.generateFLRG(flrs)
|
||||||
|
|
||||||
def forecast(self,data):
|
def forecast(self,data):
|
||||||
|
|
||||||
mv = common.fuzzyInstance(data, self.sets)
|
mv = common.fuzzyInstance(data, self.sets)
|
||||||
@ -44,19 +60,5 @@ class ConventionalFTS(fts.FTS):
|
|||||||
|
|
||||||
return denom/count
|
return denom/count
|
||||||
|
|
||||||
def generateFLRG(self, flrs):
|
|
||||||
flrgs = {}
|
|
||||||
for flr in flrs:
|
|
||||||
if flr.LHS in flrgs:
|
|
||||||
flrgs[flr.LHS].append(flr.RHS)
|
|
||||||
else:
|
|
||||||
flrgs[flr.LHS] = ConventionalFLRG(flr.LHS);
|
|
||||||
flrgs[flr.LHS].append(flr.RHS)
|
|
||||||
return (flrgs)
|
|
||||||
|
|
||||||
def train(self, data, sets):
|
|
||||||
self.sets = sets
|
|
||||||
tmpdata = common.fuzzySeries(data,sets)
|
|
||||||
flrs = common.generateNonRecurrentFLRs(tmpdata)
|
|
||||||
self.flrgs = self.generateFLRG(flrs)
|
|
||||||
|
|
||||||
|
@ -87,6 +87,6 @@ def generateNonRecurrentFLRs(fuzzyData):
|
|||||||
|
|
||||||
def generateRecurrentFLRs(fuzzyData):
|
def generateRecurrentFLRs(fuzzyData):
|
||||||
flrs = []
|
flrs = []
|
||||||
for i in range(2,len(fuzzyData)):
|
for i in np.arange(1,len(fuzzyData)):
|
||||||
flrs[i-1] = FLR(fuzzyData[i-1],fuzzyData[i])
|
flrs.append(FLR(fuzzyData[i-1],fuzzyData[i]))
|
||||||
return flrs
|
return flrs
|
||||||
|
45
yu.py
45
yu.py
@ -32,35 +32,34 @@ class WeightedFTS(fts.FTS):
|
|||||||
def __init__(self,name):
|
def __init__(self,name):
|
||||||
super(WeightedFTS, self).__init__(1,name)
|
super(WeightedFTS, self).__init__(1,name)
|
||||||
|
|
||||||
|
def generateFLRG(self, flrs):
|
||||||
|
flrgs = {}
|
||||||
|
for flr in flrs:
|
||||||
|
if flr.LHS in flrgs:
|
||||||
|
flrgs[flr.LHS].append(flr.RHS)
|
||||||
|
else:
|
||||||
|
flrgs[flr.LHS] = WeightedFLRG(flr.LHS);
|
||||||
|
flrgs[flr.LHS].append(flr.RHS)
|
||||||
|
return (flrgs)
|
||||||
|
|
||||||
|
def train(self, data, sets):
|
||||||
|
self.sets = sets
|
||||||
|
tmpdata = common.fuzzySeries(data,sets)
|
||||||
|
flrs = common.generateRecurrentFLRs(tmpdata)
|
||||||
|
self.flrgs = self.generateFLRG(flrs)
|
||||||
|
|
||||||
def forecast(self,data):
|
def forecast(self,data):
|
||||||
|
|
||||||
actual = self.fuzzy(data)
|
mv = common.fuzzyInstance(data, self.sets)
|
||||||
|
|
||||||
if actual["fuzzyset"] not in self.flrgs:
|
actual = self.sets[ np.argwhere( mv == max(mv) )[0,0] ]
|
||||||
return self.sets[actual["fuzzyset"]].centroid
|
|
||||||
|
|
||||||
flrg = self.flrgs[actual["fuzzyset"]]
|
if actual.name not in self.flrgs:
|
||||||
|
return actual.centroid
|
||||||
|
|
||||||
|
flrg = self.flrgs[actual.name]
|
||||||
|
|
||||||
mi = np.array([self.sets[s].centroid for s in flrg.RHS])
|
mi = np.array([self.sets[s].centroid for s in flrg.RHS])
|
||||||
|
|
||||||
return mi.dot( flrg.weights() )
|
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"]] = WeightedFLRG(last["fuzzyset"])
|
|
||||||
|
|
||||||
self.flrgs[last["fuzzyset"]].append(actual["fuzzyset"])
|
|
||||||
count = count + 1
|
|
||||||
last = actual
|
|
||||||
|
Loading…
Reference in New Issue
Block a user