2017-05-07 18:41:31 +04:00
|
|
|
|
"""
|
|
|
|
|
High Order Fuzzy Time Series by Hwang, Chen and Lee (1998)
|
|
|
|
|
|
|
|
|
|
Jeng-Ren Hwang, Shyi-Ming Chen, and Chia-Hoang Lee, “Handling forecasting problems using fuzzy time series,”
|
|
|
|
|
Fuzzy Sets Syst., no. 100, pp. 217–228, 1998.
|
|
|
|
|
"""
|
|
|
|
|
|
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-05-03 00:16:49 +04:00
|
|
|
|
def __init__(self, name, **kwargs):
|
2017-01-24 16:40:48 +04:00
|
|
|
|
super(HighOrderFTS, self).__init__(1, name)
|
2017-05-02 18:32:03 +04:00
|
|
|
|
self.is_high_order = True
|
|
|
|
|
self.min_order = 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-04-15 02:57:39 +04:00
|
|
|
|
def forecast(self, data, **kwargs):
|
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
|