I've been trying to learn belief propagation. Phillip Wenig has a very easy to understand python implementation available here.
Now what I'm trying to do is understand how to convert this to loopy belief propagation. I've been testing a couple different implementations:
holmes.likelihood = np.array([0, 1])
for i in range(30):
belief = watson.get_belief()
watson.likelihood = belief
print(belief)
And
holmes.likelihood = np.array([0, 1])
for i in range(30):
belief = watson.get_belief()
watson.likelihood = belief
rain.priors = rain.get_belief()
sprinkler.priors = sprinkler.get_belief()
print(belief)
Both seem to converge at [0, 1] which is the correct answer. The second implementation gets there quicker. But I'm unsure if this is the correct thing to do.
I've been working on a much larger problem and I want to make sure I'm doing the right thing. I've tried the first implementation on this larger problem and it gets better and better, but then crosses over at a point and gets more and more worse. So much so, that I'd be better off using the initial belief. I've been going off the assumption that I need to use the second implementation. However, given the size of the problem, I'm actually having arithmetic underflow when calculating likelihood, so I haven't really been able to test that solution appropriately.
Is the second solution the correct way to do this?