2016-10-19 17:27:57 +04:00
|
|
|
import numpy as np
|
2016-09-08 16:03:32 +04:00
|
|
|
from pyFTS import *
|
|
|
|
|
2016-12-22 20:36:50 +04:00
|
|
|
|
2017-01-24 16:40:48 +04:00
|
|
|
class FTS(object):
|
2016-12-22 20:36:50 +04:00
|
|
|
def __init__(self, order, name):
|
|
|
|
self.sets = {}
|
|
|
|
self.flrgs = {}
|
|
|
|
self.order = order
|
|
|
|
self.shortname = name
|
|
|
|
self.name = name
|
|
|
|
self.detail = name
|
2017-01-23 17:00:27 +04:00
|
|
|
self.isHighOrder = False
|
2017-01-25 18:17:07 +04:00
|
|
|
self.minOrder = 1
|
2017-01-11 00:05:51 +04:00
|
|
|
self.hasSeasonality = False
|
|
|
|
self.hasPointForecasting = True
|
|
|
|
self.hasIntervalForecasting = False
|
|
|
|
self.hasDistributionForecasting = False
|
|
|
|
self.dump = False
|
2017-01-26 16:19:34 +04:00
|
|
|
self.transformations = []
|
|
|
|
self.transformations_param = []
|
2017-01-30 03:59:50 +04:00
|
|
|
self.original_max = 0
|
|
|
|
self.original_min = 0
|
2016-12-22 20:36:50 +04:00
|
|
|
|
|
|
|
def fuzzy(self, data):
|
|
|
|
best = {"fuzzyset": "", "membership": 0.0}
|
|
|
|
|
|
|
|
for f in self.sets:
|
|
|
|
fset = self.sets[f]
|
|
|
|
if best["membership"] <= fset.membership(data):
|
|
|
|
best["fuzzyset"] = fset.name
|
|
|
|
best["membership"] = fset.membership(data)
|
|
|
|
|
|
|
|
return best
|
|
|
|
|
|
|
|
def forecast(self, data):
|
|
|
|
pass
|
|
|
|
|
2017-01-11 00:05:51 +04:00
|
|
|
def forecastInterval(self, data):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def forecastDistribution(self, data):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def forecastAhead(self, data, steps):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def forecastAheadInterval(self, data, steps):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def forecastAheadDistribution(self, data, steps):
|
|
|
|
pass
|
|
|
|
|
2017-01-23 17:00:27 +04:00
|
|
|
def train(self, data, sets,order=1, parameters=None):
|
2016-12-22 20:36:50 +04:00
|
|
|
pass
|
|
|
|
|
|
|
|
def getMidpoints(self, flrg):
|
|
|
|
ret = np.array([s.centroid for s in flrg.RHS])
|
|
|
|
return ret
|
|
|
|
|
2017-01-26 16:19:34 +04:00
|
|
|
def appendTransformation(self, transformation):
|
|
|
|
self.transformations.append(transformation)
|
|
|
|
|
2017-01-30 03:59:50 +04:00
|
|
|
def doTransformations(self,data,params=None,updateUoD=False):
|
2017-01-26 16:19:34 +04:00
|
|
|
ndata = data
|
2017-01-30 03:59:50 +04:00
|
|
|
if updateUoD:
|
|
|
|
if min(data) < 0:
|
|
|
|
self.original_min = min(data) * 1.1
|
|
|
|
else:
|
|
|
|
self.original_min = min(data) * 0.9
|
|
|
|
|
|
|
|
if max(data) > 0:
|
|
|
|
self.original_max = max(data) * 1.1
|
|
|
|
else:
|
|
|
|
self.original_max = max(data) * 0.9
|
|
|
|
|
2017-01-27 14:26:47 +04:00
|
|
|
if len(self.transformations) > 0:
|
|
|
|
if params is None:
|
|
|
|
params = [ None for k in self.transformations]
|
|
|
|
|
|
|
|
for c, t in enumerate(self.transformations, start=0):
|
|
|
|
ndata = t.apply(ndata,params[c])
|
2017-01-26 16:19:34 +04:00
|
|
|
|
|
|
|
return ndata
|
|
|
|
|
2017-01-27 14:26:47 +04:00
|
|
|
def doInverseTransformations(self, data, params=None):
|
2017-01-26 16:19:34 +04:00
|
|
|
ndata = data
|
2017-01-27 14:26:47 +04:00
|
|
|
if len(self.transformations) > 0:
|
|
|
|
if params is None:
|
|
|
|
params = [None for k in self.transformations]
|
|
|
|
|
|
|
|
for c, t in enumerate(reversed(self.transformations), start=0):
|
|
|
|
ndata = t.inverse(ndata, params[c])
|
2017-01-26 16:19:34 +04:00
|
|
|
|
|
|
|
return ndata
|
|
|
|
|
2016-12-22 20:36:50 +04:00
|
|
|
def __str__(self):
|
|
|
|
tmp = self.name + ":\n"
|
|
|
|
for r in sorted(self.flrgs):
|
|
|
|
tmp = tmp + str(self.flrgs[r]) + "\n"
|
|
|
|
return tmp
|