concept BP in category probabilistic programming

This is an excerpt from Manning's book Practical Probabilistic Programming.
Figaro provides implementations of EM by using inference algorithms. In this application, you’ll use belief propagation (BP). BP is a similar algorithm to VE but works faster on large models. BP works by propagating messages between the elements and goes through some number of iterations of propagating messages. When running EM with BP, you need to choose the number of iterations of both EM and BP. For this application, you’ll use the default values of 10 for both, which work well here.
BP operates using the moral graph (the initial VE graph), without adding edges. As long as the largest clique in the moral graph isn’t too large, BP is efficient. By not adding edges, BP can avoid creating large cliques, which can potentially result in exponentially faster inference than VE. This comes at a cost. Adding these edges is necessary for correct inference, so not adding the edges will result in errors. Nevertheless, inference can be approximately correct even when these edges aren’t added.
You learned in section 10.2.1 that if the moral graph is triangulated, there’s some elimination order such that no edges need to be added to produce the induced graph. As it turns out, if you run BP on a triangulated graph, it produces exactly the correct answer. In fact, the complexity of BP and VE is the same in triangulated graphs. But if you run BP on a nontriangulated graph, it’s an approximation algorithm that has the potential to be much more efficient than VE. On a nontriangulated graph, BP goes by the name of loopy BP.
BP is a message-passing algorithm. It can be best understood by considering its operation on triangulated graphs, where it’s exact. In this case, it solves a sum-of-product expression, just like VE. But rather than solving the expression by manipulating it using the rules of algebra, it solves it by passing messages between the nodes of the network. These messages are based on factor operations. I’m not going to get into how the messages are computed here, but these messages simulate the same products and sums of factors that VE performs.
There’s a significant difference between BP and VE, however. BP performs these calculations for queries on all variables in the network simultaneously. After you run BP, you can get the posterior probability of any variable, given the evidence. In a triangulated network, BP can achieve this in two passes over the network, as long as you organize the message passing in the right way. (Unfortunately, as you’ll see, Figaro can’t organize the messages to achieve this, so you’ll need more than two passes, but this property holds in principle for the BP algorithm.) This is a significant advantage of BP over VE, even in triangulated graphs, if you’re interested in querying more than one variable.
In a nontriangulated network, loopy BP works in exactly the same way as VE, except that instead of terminating after two passes (if the messages are organized right), it runs repeatedly for as long as you like. Messages are passed around the network, and if the moral graph is loopy, the messages also go around in loops. You can run BP for however many iterations you like, and get the best answer found after the given number of iterations. Ideally, the more iterations you run, the closer you’ll get to the true answer.