title: Inference in a Bayesian Network
body: <p>I need to perform some inferences on a Bayesian network, such as the example I have created below.
  <img src="https://i.stack.imgur.com/JyZCm.png" alt="Bayesian network"></p>
  
  <p>I was looking at doing something like something like this to solve an inference such as P(F| A = True, B = True). My initial approach was to do something like</p>
  
  <pre><code>For every possible output of F
    For every state of each observed variable (A,B)
       For every unobserved variable (C, D, E, G)
          // Calculate Probability
  </code></pre>
  
  <p>But I don't think this will work because we actually need to go over many variables at once, not each at a time.</p>
  
  <p>I have heard about Pearls algorithm for message passing but am yet to find a reasonable description that isn't extremely dense. For added information, these Bayesian networks are constrained as to not have more than 15-20 nodes, and we have all the conditional probability tables, the code doesn't really have to be fast or efficient.</p>
  
  <p>Basically I am looking for a way to do this, not necessarily the BEST way to do this.</p>