There seems to be two standard ways to do the message passing in belief propagation: finding the sum-product (the marginal distribution) of a variable and finding the max-product of a variable.
I found this code online made by the user krashkov that calculates the sum-product of a variable using non-loopy and loopy belief propagation (and outlines the details of the implementation and theory of belief propagation), but I am having trouble adjusting the code so that it calculates the max-product of a variable using loopy belief propagation.
I made the following changes to the code:
I changed a line in the factor_marginalization()
function to compute res_distribution = np.max(x.get_distribution(), tuple(np.where(np.isin(x.get_variables(), variables))[0]))
instead of res_distribution = np.sum(x.get_distribution(), tuple(np.where(np.isin(x.get_variables(), variables))[0]))
I changed a line in each of the __normalize_msg()
functions in the belief_propagation()
and loopy_belief_propagation()
classes to return factor(message.get_variables(), message.get_distribution())
instead of return factor(message.get_variables(), message.get_distribution()/np.sum(message.get_distribution()))
When trying to calculate the max marginals using loopy belief propagation, it seems that increasing the number of iterations in the loopy belief makes the max marginal values explode instead of calculating the actual max marginals. Could anyone help me change the code a little more to have it calculate the exact max marginals?
question from:
https://stackoverflow.com/questions/65943387/is-there-a-way-to-get-the-loopy-belief-propagation-to-compute-the-max-marginals 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…