Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
80 views
in Technique[技术] by (71.8m points)

python - Is there a way to get the loopy belief propagation to compute the max marginals?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...