PIFTS bugfix
This commit is contained in:
parent
e336a0670e
commit
ccdc74a49d
4
ifts.py
4
ifts.py
@ -48,7 +48,7 @@ class IntervalFTS(hofts.HighOrderFTS):
|
||||
|
||||
ret = []
|
||||
|
||||
for k in np.arange(self.order,l):
|
||||
for k in np.arange(self.order-1,l):
|
||||
|
||||
affected_flrgs = []
|
||||
affected_flrgs_memberships = []
|
||||
@ -60,7 +60,7 @@ class IntervalFTS(hofts.HighOrderFTS):
|
||||
count = 0
|
||||
lags = {}
|
||||
if self.order > 1:
|
||||
subset = ndata[k-self.order : k ]
|
||||
subset = ndata[k-(self.order-1) : k+1 ]
|
||||
|
||||
for instance in subset:
|
||||
mb = common.fuzzyInstance(instance, self.sets)
|
||||
|
@ -6,7 +6,9 @@ from pyFTS import *
|
||||
def GridPartitionerTrimf(data,npart,names = None,prefix = "A"):
|
||||
sets = []
|
||||
dmax = max(data)
|
||||
dmax = dmax + dmax*0.10
|
||||
dmin = min(data)
|
||||
dmin = dmin - dmin*0.10
|
||||
dlen = dmax - dmin
|
||||
partlen = dlen / npart
|
||||
partition = dmin
|
||||
|
33
pifts.py
33
pifts.py
@ -92,25 +92,34 @@ class ProbabilisticIntervalFTS(ifts.IntervalFTS):
|
||||
up = []
|
||||
lo = []
|
||||
|
||||
# Achar os conjuntos que tem pert > 0 para cada lag
|
||||
# Find the sets which membership > 0 for each lag
|
||||
count = 0
|
||||
lags = {}
|
||||
if self.order > 1:
|
||||
subset = ndata[k-(self.order-1) : k+1 ]
|
||||
|
||||
for instance in subset:
|
||||
mb = common.fuzzyInstance(instance, self.sets)
|
||||
tmp = np.argwhere( mb )
|
||||
idx = np.ravel(tmp) #flat the array
|
||||
idx = np.ravel(tmp) #flatten the array
|
||||
|
||||
if idx.size == 0: # the element is out of the bounds of the Universe of Discourse
|
||||
if instance <= self.sets[0].lower:
|
||||
idx = [0]
|
||||
if instance >= self.sets[-1].upper:
|
||||
idx = [len(self.sets)-1]
|
||||
|
||||
lags[count] = idx
|
||||
count = count + 1
|
||||
|
||||
# Constrói uma árvore com todos os caminhos possíveis
|
||||
|
||||
# Build the tree with all possible paths
|
||||
|
||||
root = tree.FLRGTreeNode(None)
|
||||
|
||||
self.buildTree(root,lags,0)
|
||||
|
||||
# Traça os possíveis caminhos e costrói as PFLRG's
|
||||
# Trace the possible paths and build the PFLRG's
|
||||
|
||||
for p in root.paths():
|
||||
path = list(reversed(list(filter(None.__ne__, p))))
|
||||
@ -120,7 +129,7 @@ class ProbabilisticIntervalFTS(ifts.IntervalFTS):
|
||||
##
|
||||
affected_flrgs.append( flrg )
|
||||
|
||||
# Acha a pertinência geral de cada FLRG
|
||||
# Find the general membership of FLRG
|
||||
affected_flrgs_memberships.append(min(self.getSequenceMembership(subset, flrg.LHS)))
|
||||
else:
|
||||
|
||||
@ -144,16 +153,22 @@ class ProbabilisticIntervalFTS(ifts.IntervalFTS):
|
||||
|
||||
# gerar o intervalo
|
||||
norm = sum(norms)
|
||||
ret.append( [ sum(lo)/norm, sum(up)/norm ] )
|
||||
if norm == 0:
|
||||
ret.append( [ 0, 0 ] )
|
||||
else:
|
||||
ret.append( [ sum(lo)/norm, sum(up)/norm ] )
|
||||
|
||||
return ret
|
||||
|
||||
def forecastAhead(self,data,steps):
|
||||
ret = [[data[k],data[k]] for k in np.arange(len(data)-self.order,len(data))]
|
||||
for k in np.arange(self.order,steps):
|
||||
lower = self.forecast( [ret[x][0] for x in np.arange(k-self.order,k)] )
|
||||
upper = self.forecast( [ret[x][1] for x in np.arange(k-self.order,k)] )
|
||||
ret.append([np.min(lower),np.max(upper)])
|
||||
if ret[-1][0] <= self.sets[0].lower and ret[-1][0] >= self.sets[-1].upper:
|
||||
ret.append(ret[-1])
|
||||
else:
|
||||
lower = self.forecast( [ret[x][0] for x in np.arange(k-self.order,k)] )
|
||||
upper = self.forecast( [ret[x][1] for x in np.arange(k-self.order,k)] )
|
||||
ret.append([np.min(lower),np.max(upper)])
|
||||
|
||||
return ret
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user