Cleaning the sources
This commit is contained in:
parent
7c1e79b30d
commit
84b29bcdf7
2
ifts.py
2
ifts.py
@ -27,8 +27,6 @@ class IntervalFTS(hofts.HighOrderFTS):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
def getSequenceMembership(self, data, fuzzySets):
|
def getSequenceMembership(self, data, fuzzySets):
|
||||||
#print(data)
|
|
||||||
#print(fuzzySets)
|
|
||||||
mb = [ fuzzySets[k].membership( data[k] ) for k in np.arange(0,len(data)) ]
|
mb = [ fuzzySets[k].membership( data[k] ) for k in np.arange(0,len(data)) ]
|
||||||
return mb
|
return mb
|
||||||
|
|
||||||
|
25
pifts.py
25
pifts.py
@ -67,8 +67,6 @@ class ProbabilisticIntervalFTS(ifts.IntervalFTS):
|
|||||||
tmp = self.flrgs[ flrg.strLHS() ]
|
tmp = self.flrgs[ flrg.strLHS() ]
|
||||||
ret = sum(np.array([ tmp.getProbability(s) * self.setsDict[s].upper for s in tmp.RHS]))
|
ret = sum(np.array([ tmp.getProbability(s) * self.setsDict[s].upper for s in tmp.RHS]))
|
||||||
else:
|
else:
|
||||||
#print("hit" + flrg.strLHS())
|
|
||||||
#ret = flrg.LHS[-1].upper
|
|
||||||
ret = sum(np.array([ 0.33 * s.upper for s in flrg.LHS]))
|
ret = sum(np.array([ 0.33 * s.upper for s in flrg.LHS]))
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@ -77,17 +75,13 @@ class ProbabilisticIntervalFTS(ifts.IntervalFTS):
|
|||||||
tmp = self.flrgs[ flrg.strLHS() ]
|
tmp = self.flrgs[ flrg.strLHS() ]
|
||||||
ret = sum(np.array([ tmp.getProbability(s) * self.setsDict[s].lower for s in tmp.RHS]))
|
ret = sum(np.array([ tmp.getProbability(s) * self.setsDict[s].lower for s in tmp.RHS]))
|
||||||
else:
|
else:
|
||||||
#print("hit" + flrg.strLHS())
|
|
||||||
#ret = flrg.LHS[-1].lower
|
|
||||||
ret = sum(np.array([ 0.33 * s.lower for s in flrg.LHS]))
|
ret = sum(np.array([ 0.33 * s.lower for s in flrg.LHS]))
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def forecast(self,data):
|
def forecast(self,data):
|
||||||
|
|
||||||
ndata = np.array(data)
|
ndata = np.array(data)
|
||||||
|
|
||||||
#print(ndata)
|
|
||||||
|
|
||||||
l = len(ndata)
|
l = len(ndata)
|
||||||
|
|
||||||
ret = []
|
ret = []
|
||||||
@ -115,16 +109,14 @@ class ProbabilisticIntervalFTS(ifts.IntervalFTS):
|
|||||||
idx = np.ravel(tmp) #flatten 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 idx.size == 0: # the element is out of the bounds of the Universe of Discourse
|
||||||
#print("high order - idx.size == 0 - " + str(instance))
|
|
||||||
if math.ceil(instance) <= self.sets[0].lower:
|
if math.ceil(instance) <= self.sets[0].lower:
|
||||||
idx = [0]
|
idx = [0]
|
||||||
elif math.ceil(instance) >= self.sets[-1].upper:
|
elif math.ceil(instance) >= self.sets[-1].upper:
|
||||||
idx = [len(self.sets)-1]
|
idx = [len(self.sets)-1]
|
||||||
#print(idx)
|
|
||||||
else:
|
else:
|
||||||
raise Exception( instance )
|
raise Exception( instance )
|
||||||
#print(idx)
|
|
||||||
lags[count] = idx
|
lags[count] = idx
|
||||||
count = count + 1
|
count = count + 1
|
||||||
|
|
||||||
# Build the tree with all possible paths
|
# Build the tree with all possible paths
|
||||||
@ -147,7 +139,7 @@ class ProbabilisticIntervalFTS(ifts.IntervalFTS):
|
|||||||
|
|
||||||
# Find the general membership of FLRG
|
# Find the general membership of FLRG
|
||||||
affected_flrgs_memberships.append(min(self.getSequenceMembership(subset, flrg.LHS)))
|
affected_flrgs_memberships.append(min(self.getSequenceMembership(subset, flrg.LHS)))
|
||||||
#print(self.getSequenceMembership(subset, flrg.LHS))
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
mv = common.fuzzyInstance(ndata[k],self.sets) # get all membership values
|
mv = common.fuzzyInstance(ndata[k],self.sets) # get all membership values
|
||||||
@ -155,20 +147,17 @@ class ProbabilisticIntervalFTS(ifts.IntervalFTS):
|
|||||||
idx = np.ravel(tmp) # flatten 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 idx.size == 0: # the element is out of the bounds of the Universe of Discourse
|
||||||
#print("idx.size == 0")
|
|
||||||
if math.ceil(ndata[k]) <= self.sets[0].lower:
|
if math.ceil(ndata[k]) <= self.sets[0].lower:
|
||||||
idx = [0]
|
idx = [0]
|
||||||
elif math.ceil(ndata[k]) >= self.sets[-1].upper:
|
elif math.ceil(ndata[k]) >= self.sets[-1].upper:
|
||||||
idx = [len(self.sets)-1]
|
idx = [len(self.sets)-1]
|
||||||
#print(idx)
|
|
||||||
else:
|
else:
|
||||||
raise Exception( ndata[k] )
|
raise Exception( ndata[k] )
|
||||||
#print(idx)
|
|
||||||
for kk in idx:
|
for kk in idx:
|
||||||
flrg = hofts.HighOrderFLRG(self.order)
|
flrg = hofts.HighOrderFLRG(self.order)
|
||||||
flrg.appendLHS(self.sets[ kk ])
|
flrg.appendLHS(self.sets[ kk ])
|
||||||
affected_flrgs.append( flrg )
|
affected_flrgs.append( flrg )
|
||||||
#print(mv[kk])
|
|
||||||
affected_flrgs_memberships.append(mv[kk])
|
affected_flrgs_memberships.append(mv[kk])
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
@ -186,7 +175,6 @@ class ProbabilisticIntervalFTS(ifts.IntervalFTS):
|
|||||||
norm = sum(norms)
|
norm = sum(norms)
|
||||||
if norm == 0:
|
if norm == 0:
|
||||||
ret.append( [ 0, 0 ] )
|
ret.append( [ 0, 0 ] )
|
||||||
print("disparou")
|
|
||||||
else:
|
else:
|
||||||
ret.append( [ sum(lo)/norm, sum(up)/norm ] )
|
ret.append( [ sum(lo)/norm, sum(up)/norm ] )
|
||||||
|
|
||||||
@ -194,12 +182,11 @@ class ProbabilisticIntervalFTS(ifts.IntervalFTS):
|
|||||||
|
|
||||||
def forecastAhead(self,data,steps):
|
def forecastAhead(self,data,steps):
|
||||||
ret = [[data[k],data[k]] for k in np.arange(len(data)-self.order,len(data))]
|
ret = [[data[k],data[k]] for k in np.arange(len(data)-self.order,len(data))]
|
||||||
#print(ret)
|
|
||||||
for k in np.arange(self.order-1,steps):
|
for k in np.arange(self.order-1,steps):
|
||||||
|
|
||||||
if ret[-1][0] <= self.sets[0].lower and ret[-1][1] >= self.sets[-1].upper:
|
if ret[-1][0] <= self.sets[0].lower and ret[-1][1] >= self.sets[-1].upper:
|
||||||
ret.append(ret[-1])
|
ret.append(ret[-1])
|
||||||
#print("disparou")
|
|
||||||
else:
|
else:
|
||||||
lower = self.forecast( [ret[x][0] for x in np.arange(k-self.order,k)] )
|
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)] )
|
upper = self.forecast( [ret[x][1] for x in np.arange(k-self.order,k)] )
|
||||||
|
Loading…
Reference in New Issue
Block a user