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