Personal tools
You are here: Home Discussion

Discussion

Up to the Bugs Forum
Please feel free to communicate anything you feel could help this project move on. You can receive an email each time a new message is posted by setting up your personal preferences.

problem with Jointree

Posted by thomas at February 20. 2007
Hi All.
Unfortunately, I have a problem using Jointree in the folowing context:

from OpenBayes import MCMCEngine, JoinTree, learning, bayesnet
from copy import deepcopy
from time import time

cases = [{'x1':1,'x2':0,'x3':1,'x4':0, },
{'x1':1,'x2':1,'x3':0,'x4':0, },
{'x1':0,'x2':1,'x3':0,'x4':0,}]

# Create a new BNet with no edges
G2 = bayesnet.BNet('test BN')
x1,x2,x3,x4 = [G2.add_v(bayesnet.BVertex(nm,True,2)) for nm in 'x1 x2 x3 x4'.split()]
G2.InitDistributions()

x1.setDistributionParameters([0.5 ,0.5 ])
x2.setDistributionParameters([0.7 ,0.3 ])
x3.setDistributionParameters([0.5 ,0.5 ])
x4.setDistributionParameters([0.35,0.65])

# Learn the structure
struct_engine = learning.GreedyStructLearningEngine(G2)
struct_engine.StructLearning(cases)

G2=struct_engine.BNet

# Inference
ie=JoinTree(G2)
ie.SetObs({'x1':1})
print ie.Marginalise('x3')

# this results to:
#
#Traceback (most recent call last):
# File "testbayes1.py", line 24, in
# ie=JoinTree(G2)
# File "C:\Python25\Lib\site-packages\OpenBayes\inference.py", line 426, in __init__
# self.GlobalPropagation()
# File "C:\Python25\Lib\site-packages\OpenBayes\inference.py", line 514, in GlobalPropagation
# start.CollectEvidence()
# File "C:\Python25\Lib\site-packages\OpenBayes\inference.py", line 187, in CollectEvidence
# if not v.marked: v.CollectEvidence(self)
# File "C:\Python25\Lib\site-packages\OpenBayes\inference.py", line 189, in CollectEvidence
# if not X == None: self.MessagePass(X)
# File "C:\Python25\Lib\site-packages\OpenBayes\inference.py", line 168, in MessagePass
# newphiR = self.potential + e.potential # phiR = sum(X/R)phiX
# File "C:\Python25\lib\site-packages\OpenBayes\potentials.py", line 156, in __add__
# return self.Marginalise(var)
# File "C:\Python25\lib\site-packages\OpenBayes\potentials.py", line 119, in Marginalise
# return self.__class__(newnames,temp.shape,temp)
#AttributeError: 'float' object has no attribute 'shape'

The main idea is just that i want to structlearn a network and then do some inferences with it.
Posted by obadmin at February 21. 2007
Hi thomas,

it seems like the ConnexeInferenceEngine does not work correctly or is not used at all...

The ConnexeInferenceEngine was created to treat problems like yours. It separates the BNet into independant compounds that are not connected between them, and creates a different inference engine for each one of them. Viewed from the user, it should be completely transparent. For example when you choose to marginalise a node, the corresponding inference engine (inside the ConnexeInference) that contains that node is used and the nodes that are not connected to that subset are not used at all.

For the moment I'm working on the Gaussian Distributions so I'll check your problem after that. If all goes well, probably next week I'll start working on your problem.

However, if you wish to participate to OpenBayes, you could try to solve this problem by yourself. In that case, I'll be glad to help you track down the bug and solve it.

Please tell me your plans

Kosta

Posted by Francois at February 26. 2007
Hello,

I think I fixed the bug. I have sent my code to Kosta. He will post it after he checked it.

François
Posted by obadmin at March 06. 2007
Hello,

If anybody needs François code for SEM learning for not fully connected networks (using the ConnexeInferenceEngine) you can grab it here :

http://svn.berlios.de/wsvn/pybayes/branches/Learning/?rev=0&sc=0

Learningwanna.py should be used instead of learning.py

This will be included in the new version of OpenBayes.

Since I'm working on the new version for the moment, I have decided to stop correcting bugs in the old version, since the structure of OpenBayes is under modification and this would mean double work.

I'm sorry for any inconvenience, and I assure you I'll do my best for this new version to come out as soon as possible including all the features and bug fixes that you have requested.

kosta
Powered by Ploneboard

Powered by Plone, the Open Source Content Management System

This site conforms to the following standards: