Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loopy Belief Propagation code example

Tags:

bayesian

Does anybody know of a working code example of the sum-product algorithm for (loopy) belief for Bayesian Networks? I have scoured the earth for a couple days but haven't had much luck. I'm indifferent to which language it is in.

All the documents I have found on the topic are full of arcane and absurdly ambiguous mathspeak. It doesn't seem like a difficult algorithm, but I can't be sure because some of the tricky bits are glossed over so much.

Alternately, an example that uses real numbers (rather than variable names) would probably do the trick as well.

like image 532
Gabe Johnson Avatar asked Mar 02 '10 21:03

Gabe Johnson


2 Answers

I'm in a similar situation. I'm using the book "Pattern Recognition and Machine Learning" by Christopher M. Bishop for a theoretical introduction, even though I do want to use the algorithm in some other context. The chapter on "max-product" and "sum-product" describes belief propagation, although it is very mathematical.

I'm still looking for a small numerical example so if you find one I'd be very interested.

Meanwhile you can take a look at libDAI, an open source library that implements BP.

like image 170
dudemeister Avatar answered Nov 26 '22 22:11

dudemeister


I've implemented Pearl's belief propagation algorithm for Bayesian Networks. It supports loopy propagation as well, as it will terminate when the informed belief values converge to within 0.001.

All the code is in Java, and it may be found in my Google code pen-ui svn repo.

This doesn't explicitly make a factor graph.

The class "Support" has a main function, and a couple static methods that create small networks that you can play with. In particular I implemented the three-node Burlar-FreightTruck-Alarm network found in Neapolitan's book, and my numbers check out. (No promises beyond that!)

like image 34
Gabe Johnson Avatar answered Nov 26 '22 20:11

Gabe Johnson