tags:

views:

408

answers:

2

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.

+1  A: 

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.

dudemeister
The book: "Learning Bayesian Networks" by Neapolitan gives two versions of the algorithm. No detail is left out, though it has some crufty math syntax. He also gives *copious* numerical examples of what happens when the algorithms run. I can send you the PDF if you want (over 700 pages, bleh). It doesn't explicitly address loopy propagation, but that's something I can probably figure out. Good resources here: http://www.mcs.vuw.ac.nz/courses/COMP421/2008T1/documents/marcus/I'm implementing it myself (in Java) so I'll post something when it works and is debugged.
Gabe Johnson
Also, see http://www.mcs.vuw.ac.nz/courses/COMP421/2008T1/code/GM/markov.py for a Python implementation. Though I am convinced it is buggy, and I don't understand it.
Gabe Johnson
Got the book by Neapolitan from the library. Really nice to have some good examples! Thanks for the tip. Unfortunately it does not explain the relation of bayesian networks, markov nets and factor graphs which seems to be link I'm currently missing to fully understand loopy BP. Some other resources I somewhat found useful:http://www.stanford.edu/~montanar/BOOK/partD.pdfhttp://www.kyb.tuebingen.mpg.de/bs/people/jorism/articles/thesis-mooij-hyperref.pdf
dudemeister
+1  A: 

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!)

Gabe Johnson