SFTS
This commit is contained in:
parent
682dd907e6
commit
d0c7753b2b
2
chen.py
2
chen.py
@ -42,8 +42,6 @@ class ConventionalFTS(fts.FTS):
|
|||||||
|
|
||||||
def forecast(self,data):
|
def forecast(self,data):
|
||||||
|
|
||||||
l = 1
|
|
||||||
|
|
||||||
ndata = np.array(data)
|
ndata = np.array(data)
|
||||||
|
|
||||||
l = len(ndata)
|
l = len(ndata)
|
||||||
|
62
sfts.py
62
sfts.py
@ -10,48 +10,56 @@ class SeasonalFLRG(fts.FTS):
|
|||||||
self.RHS.append(c)
|
self.RHS.append(c)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
tmp = self.LHS + " -> "
|
tmp = str(self.LHS) + " -> "
|
||||||
tmp2 = ""
|
tmp2 = ""
|
||||||
for c in self.RHS:
|
for c in sorted(self.RHS, key=lambda s: s.name):
|
||||||
if len(tmp2) > 0:
|
if len(tmp2) > 0:
|
||||||
tmp2 = tmp2 + ","
|
tmp2 = tmp2 + ","
|
||||||
tmp2 = tmp2 + c
|
tmp2 = tmp2 + c.name
|
||||||
return tmp + tmp2
|
return tmp + tmp2
|
||||||
|
|
||||||
|
|
||||||
class SeasonalFTS(fts.FTS):
|
class SeasonalFTS(fts.FTS):
|
||||||
def __init__(self,name):
|
def __init__(self,name):
|
||||||
super(SeasonalFTS, self).__init__(1,name)
|
super(SeasonalFTS, self).__init__(1,name)
|
||||||
|
self.seasonality = 1
|
||||||
|
|
||||||
|
|
||||||
|
def generateFLRG(self, flrs):
|
||||||
|
flrgs = []
|
||||||
|
season = 1
|
||||||
|
for flr in flrs:
|
||||||
|
if len(flrgs) < self.seasonality:
|
||||||
|
flrgs.append(SeasonalFLRG(season))
|
||||||
|
|
||||||
|
flrgs[season].append(flr.RHS)
|
||||||
|
|
||||||
|
season = (season + 1) % (self.seasonality + 1)
|
||||||
|
|
||||||
|
if season == 0: season = 1
|
||||||
|
|
||||||
|
return (flrgs)
|
||||||
|
|
||||||
|
def train(self, data, sets, seasonality):
|
||||||
|
self.sets = sets
|
||||||
|
self.seasonality = seasonality
|
||||||
|
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)
|
ndata = np.array(data)
|
||||||
|
|
||||||
if actual["fuzzyset"] not in self.flrgs:
|
l = len(ndata)
|
||||||
return self.sets[actual["fuzzyset"]].centroid
|
|
||||||
|
|
||||||
flrg = self.flrgs[actual["fuzzyset"]]
|
ret = []
|
||||||
|
|
||||||
mi = np.array([self.sets[s].centroid for s in flrg.RHS])
|
for k in np.arange(1,l):
|
||||||
|
flrg = self.flrgs[ data[k] ]
|
||||||
|
|
||||||
return mi.dot( flrg.weights() )
|
mp = self.getMidpoints(flrg)
|
||||||
|
|
||||||
def train(self, data, sets):
|
ret.append(sum(mp)/len(mp))
|
||||||
last = {"fuzzyset":"", "membership":0.0}
|
|
||||||
actual = {"fuzzyset":"", "membership":0.0}
|
|
||||||
|
|
||||||
for s in sets:
|
return ret
|
||||||
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"]] = SeasonalFLRG(last["fuzzyset"])
|
|
||||||
|
|
||||||
self.flrgs[last["fuzzyset"]].append(actual["fuzzyset"])
|
|
||||||
count = count + 1
|
|
||||||
last = actual
|
|
||||||
|
Loading…
Reference in New Issue
Block a user