Construção da FLRGTree ok

This commit is contained in:
Petrônio Cândido de Lima e Silva 2016-10-21 11:23:55 -02:00
parent bea7bc94e2
commit a719fffe45
2 changed files with 34 additions and 34 deletions

45
ifts.py
View File

@ -19,6 +19,16 @@ class IntervalFTS(hofts.HighOrderFTS):
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
def buildTree(self,node, lags, level):
if level >= self.order:
return
for s in lags[level]["sets"]:
node.appendChild(tree.FLRGTreeNode(s))
for child in node.getChildren():
self.buildTree(child,lags,level+1)
def forecast(self,data): def forecast(self,data):
ndata = np.array(data) ndata = np.array(data)
@ -35,7 +45,6 @@ class IntervalFTS(hofts.HighOrderFTS):
# Achar os conjuntos que tem pert > 0 para cada lag # Achar os conjuntos que tem pert > 0 para cada lag
count = 0 count = 0
lags = {} lags = {}
combinations = 1
for instance in ndata[k-self.order : k]: for instance in ndata[k-self.order : k]:
mb = common.fuzzyInstance(instance, self.sets) mb = common.fuzzyInstance(instance, self.sets)
tmp = np.argwhere( mb ) tmp = np.argwhere( mb )
@ -47,36 +56,28 @@ class IntervalFTS(hofts.HighOrderFTS):
lag["memberships"] = [mb[ k ] for k in idx] lag["memberships"] = [mb[ k ] for k in idx]
lag["count"] = len(idx) lag["count"] = len(idx)
lags[count] = lag lags[count] = lag
combinations = combinations * lag["count"]
count = count + 1 count = count + 1
print(combinations) # Constrói uma árvore com todos os caminhos possíveis
root = tree.FLRGTreeNode(None)
# Build a tree exploring all possibilities self.buildTree(root,lags,0)
# Trace each path from leaf to roots and reverse path # Traça os possíveis caminhos e costróis as HOFLRG's
print(root)
# ------- # -------
#return lags for p in root.paths():
path = list(reversed(list(filter(None.__ne__, p))))
print(path)
#for n in tree.flat(p):
# print(n)
#print("--")
wflrgs = {} return
# 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 a pert geral de cada FLRG

13
tree.py
View File

@ -17,14 +17,13 @@ class FLRGTreeNode:
for child in self.children: for child in self.children:
yield child yield child
def getPaths(self): def paths(self, acc=[]):
if len(self.children) > 0: if len(self.children) == 0:
yield [self.value]+acc
for child in self.children: for child in self.children:
tmp = [self.value] for leaf_path in child.paths([self.value]+acc): # these two
tmp.extend(child.getPaths()) yield leaf_path
yield tmp
else:
yield self.value
def getStr(self,k): def getStr(self,k):
if self.isRoot: if self.isRoot: