2016-10-18 15:50:27 +04:00
|
|
|
import numpy as np
|
2016-12-22 20:36:50 +04:00
|
|
|
from pyFTS.common import FuzzySet,FLR,Transformations
|
2017-01-11 00:05:51 +04:00
|
|
|
from pyFTS import fts
|
2016-12-22 20:36:50 +04:00
|
|
|
|
2016-09-08 16:03:32 +04:00
|
|
|
|
|
|
|
class HighOrderFTS(fts.FTS):
|
2017-01-24 16:40:48 +04:00
|
|
|
def __init__(self, name):
|
|
|
|
super(HighOrderFTS, self).__init__(1, name)
|
2017-01-23 17:00:27 +04:00
|
|
|
self.isHighOrder = True
|
2017-01-25 18:17:07 +04:00
|
|
|
self.minOrder = 2
|
2017-01-24 16:40:48 +04:00
|
|
|
self.name = "Hwang High Order FTS"
|
|
|
|
self.shortname = "Hwang" + name
|
|
|
|
self.detail = "Hwang"
|
2016-12-22 20:36:50 +04:00
|
|
|
|
2017-01-23 17:00:27 +04:00
|
|
|
def forecast(self, data):
|
2017-01-27 14:26:47 +04:00
|
|
|
|
|
|
|
ndata = self.doTransformations(data)
|
|
|
|
|
2016-12-22 20:36:50 +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))])
|
2016-09-02 22:55:55 +04:00
|
|
|
|
2017-01-23 17:00:27 +04:00
|
|
|
ret = []
|
|
|
|
|
2017-01-27 14:26:47 +04:00
|
|
|
for t in np.arange(self.order-1, len(ndata)):
|
2016-09-02 22:55:55 +04:00
|
|
|
|
2017-01-23 17:00:27 +04:00
|
|
|
for s in range(len(self.sets)):
|
2017-01-27 14:26:47 +04:00
|
|
|
cn[s] = self.sets[s].membership(ndata[t])
|
2017-01-23 17:00:27 +04:00
|
|
|
for w in range(self.order - 1):
|
2017-01-27 14:26:47 +04:00
|
|
|
ow[w, s] = self.sets[s].membership(ndata[t - w])
|
2017-01-23 17:00:27 +04:00
|
|
|
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
|
2017-01-24 16:40:48 +04:00
|
|
|
count += 1.0
|
2017-01-23 17:00:27 +04:00
|
|
|
ret.append(out / count)
|
2016-09-02 22:55:55 +04:00
|
|
|
|
2017-01-27 14:26:47 +04:00
|
|
|
ret = self.doInverseTransformations(ret, params=[data[self.order - 1:]])
|
|
|
|
|
2017-01-23 17:00:27 +04:00
|
|
|
return ret
|
|
|
|
|
2017-01-24 16:40:48 +04:00
|
|
|
def train(self, data, sets, order=1, parameters=None):
|
2017-01-23 17:00:27 +04:00
|
|
|
self.sets = sets
|
|
|
|
self.order = order
|