2016-10-18 15:50:27 +04:00
|
|
|
import numpy as np
|
2016-09-08 16:03:32 +04:00
|
|
|
from pyFTS import *
|
|
|
|
|
|
|
|
class HighOrderFTS(fts.FTS):
|
2016-09-02 22:55:55 +04:00
|
|
|
def __init__(self,order,name):
|
|
|
|
super(HighOrderFTS, self).__init__(order,name)
|
|
|
|
|
2016-10-18 16:09:36 +04:00
|
|
|
def forecast(self,data,t):
|
2016-09-02 22:55:55 +04:00
|
|
|
cn = np.array([0.0 for k in range(len(self.sets))])
|
|
|
|
ow = np.array([[0.0 for k in range(len(self.sets))] for z in range(self.order-1)])
|
|
|
|
rn = np.array([[0.0 for k in range(len(self.sets))] for z in range(self.order-1)])
|
|
|
|
ft = np.array([0.0 for k in range(len(self.sets))])
|
|
|
|
|
|
|
|
for s in range(len(self.sets)):
|
|
|
|
cn[s] = self.sets[s].membership(data[t])
|
|
|
|
for w in range(self.order-1):
|
|
|
|
ow[w,s] = self.sets[s].membership(data[t-w])
|
|
|
|
rn[w,s] = ow[w,s] * cn[s]
|
|
|
|
ft[s] = max(ft[s],rn[w,s])
|
|
|
|
mft = max(ft)
|
|
|
|
out = 0.0
|
|
|
|
count = 0.0
|
|
|
|
for s in range(len(self.sets)):
|
|
|
|
if ft[s] == mft:
|
|
|
|
out = out + self.sets[s].centroid
|
|
|
|
count = count + 1.0
|
|
|
|
return out / count
|
|
|
|
|
|
|
|
|
2016-10-18 16:09:36 +04:00
|
|
|
def train(self, data, sets):
|
2016-09-02 22:55:55 +04:00
|
|
|
self.sets = sets
|
|
|
|
|
|
|
|
def predict(self,data,t):
|
2016-10-18 16:09:36 +04:00
|
|
|
return self.forecast(data,t)
|
2016-09-02 22:55:55 +04:00
|
|
|
|
|
|
|
def predictDiff(self,data,t):
|
2016-10-18 16:09:36 +04:00
|
|
|
return data[t] + self.forecast(common.differential(data),t)
|