Loopy Belief Propagation code example

Gabe Johnson picture Gabe Johnson · Mar 2, 2010 · Viewed 7.6k times · Source

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.

Answer

dudemeister picture dudemeister · Mar 4, 2010

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.