Marginal Inference in Bayesian Networks with pyBN

Marginal inference is a task concerned with answering probability queries of the form P(X|E), where X is a set of variables of interest and E is the set of evidence variables. Performing marginal inference is an important task because it allows you to calculate and view updated beliefs in the face of new data. The pyBN module makes this easy.

Let's start by loading the pyBN package and reading the "Earthquake" network included in the /data/ folder


In [15]:
from pyBN import *
bn = read_bn('data/earthquake.bn')

As with any new Bayesian network, it helps to look at its attributes:


In [16]:
import json
print json.dumps(bn.E,indent=2)


{
  "Burglary": [
    "Alarm"
  ], 
  "MaryCalls": [], 
  "Alarm": [
    "JohnCalls", 
    "MaryCalls"
  ], 
  "JohnCalls": [], 
  "Earthquake": [
    "Alarm"
  ]
}

Here, we see that the network consists of five nodes - two priors ('Burglary' and 'Earthquake') converging on 'Alarm', which in turn spawns two leaf nodes ('MaryCalls' and 'JohnCalls')


In [ ]: