18e795bcd3
- Issue #2 - PEP 8 compliance - Issue #3 - Code documentation with PEP 257 compliance
49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
import numpy as np
|
|
from pyFTS.common import FuzzySet,FLR,Transformations
|
|
from pyFTS import fts
|
|
|
|
|
|
class HighOrderFTS(fts.FTS):
|
|
def __init__(self, name, **kwargs):
|
|
super(HighOrderFTS, self).__init__(1, name)
|
|
self.is_high_order = True
|
|
self.min_order = 2
|
|
self.name = "Hwang High Order FTS"
|
|
self.shortname = "Hwang" + name
|
|
self.detail = "Hwang"
|
|
|
|
def forecast(self, data, **kwargs):
|
|
|
|
ndata = self.doTransformations(data)
|
|
|
|
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))])
|
|
|
|
ret = []
|
|
|
|
for t in np.arange(self.order-1, len(ndata)):
|
|
|
|
for s in range(len(self.sets)):
|
|
cn[s] = self.sets[s].membership(ndata[t])
|
|
for w in range(self.order - 1):
|
|
ow[w, s] = self.sets[s].membership(ndata[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 += 1.0
|
|
ret.append(out / count)
|
|
|
|
ret = self.doInverseTransformations(ret, params=[data[self.order - 1:]])
|
|
|
|
return ret
|
|
|
|
def train(self, data, sets, order=1, parameters=None):
|
|
self.sets = sets
|
|
self.order = order |