From 01cdf092eb52630aede29bf550a61d294975c99b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=C3=B4nio=20C=C3=A2ndido=20de=20Lima=20e=20Silva?= Date: Thu, 20 Oct 2016 11:57:59 -0200 Subject: [PATCH] =?UTF-8?q?IFTS=20implementa=C3=A7=C3=A3o=20inicial=20dife?= =?UTF-8?q?rente=20da=20rfts,=20com=20suporte=20=C3=A0=20high=20order?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ifts.py | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 ifts.py diff --git a/ifts.py b/ifts.py new file mode 100644 index 0000000..f116bb1 --- /dev/null +++ b/ifts.py @@ -0,0 +1,103 @@ +import numpy as np +from pyFTS import * + + +class IntervalFTS(hofts.HighOrderFTS): + def __init__(self,name): + super(IntervalFTS, self).__init__(name) + self.flrgs = {} + + def getUpper(self,flrg): + ret = np.array([s.upper for s in flrg.RHS]) + return ret + + def getLower(self,flrg): + ret = np.array([s.lower for s in flrg.RHS]) + return ret + + def getSequenceMembership(self, data, fuzzySets): + mb = [ fuzzySets[k].membership( data[k] ) for k in np.arange(0,len(data)) ] + return mb + + def forecast(self,data): + + ndata = np.array(data) + + l = len(ndata) + + ret = [] + + for k in np.arange(self.order+1,l): + + up = [] + lo = [] + + # Achar os conjuntos que tem pert > 0 para cada lag + count = 0 + lags = {} + combinations = 1 + for instance in ndata[k-self.order : k]: + mb = common.fuzzyInstance(instance, self.sets) + tmp = np.argwhere( mb ) + idx = np.ravel(tmp) #flatten + + lag = {} + lag["id"] = count + lag["sets"] = idx + lag["memberships"] = [mb[ k ] for k in idx] + lag["count"] = len(idx) + lags[count] = lag + combinations = combinations * lag["count"] + count = count + 1 + + print(combinations) + + + # Build a tree exploring all possibilities + + # Trace each path from leaf to roots and reverse path + + # ------- + + #return lags + + wflrgs = {} + + # Gerar as permutações possíveis e as FLRG's correspondentes + lag_inc = [0 for k in np.arange(0,self.order) ] + isComplete = False + while (isComplete): + flrg = hofts.HighOrderFLRG(self.order) + + flrg.appendLHS( self.sets[ lag_inc[0] ] ) + + for lag_count in np.arange(1,self.order): + if lag_count > 1: lag_inc[ lag_count - 1 ] = 0 + +# for + + #lag_count = lag_count + 1 + + # Achar a pert geral de cada FLRG + + # achar o os bounds de cada FLRG + + # gerar o intervalo + +# tmpdata = common.fuzzySeries(XX,self.sets) +# tmpflrg = HighOrderFLRG(self.order) + +# for s in tmpdata: tmpflrg.appendLHS(s) + +# if tmpflrg.strLHS() not in self.flrgs: +# ret.append(tmpdata[-1].centroid) +# else: +# flrg = self.flrgs[tmpflrg.strLHS()] +# mp = self.getMidpoints(flrg) + +# ret.append(sum(mp)/len(mp)) + +# return ret + + +