8.3 Belief Networks


A Bayesian network, also called a belief network, is a model of conditional dependence among a set of random variables. The conditional independence in a Bayesian network takes in an ordering of the variables, and results in an acyclic directed graph (DAG). Associated with each node of a Bayesian network is a set of conditional probability distributions (factors) that specify the conditional probability of each variable given its parents (which includes the prior probabilities of those variables with no parents).

You can run each cell by selecting it and pressing Ctrl+Enter in Windows or Shift+Return in MacOS. Alternatively, you can click the Play button in the toolbar, to the left of the stop button. For more information, check out our AISpace2 Tutorial.

Feel free to modify our codes either in this notebook or somewhere outside (e.g. python files in /aipython/). If you want to modify our codes outside, you might find this helpful for how your changes can take effect.

You need to run the following command to import our pre-defined problems.

In [ ]:
# Run this to import pre-defined problems
from aipython.probGraphicalModels import bn_simple1, bn_simple2, bn_simple3, bn_grass_watering, bn_fire_alarm, bn_diagnosis, bn_diagnosis_extended, bn_conditional_independence, bn_car_starting, bn_electrical_diagnosis, bn_hailfinder

You can also define your own problems (how?).

You need to run the following command to import utilities that support your self-defined problems.

In [ ]:
from aipython.probFactors import Prob
from aipython.probGraphicalModels import Belief_network
from aipython.probVariables import Variable

In [ ]:
from aipython.probBayesianNetwork import Bayesian_Network

bn = Bayesian_Network(problem=bn_simple1)

# Visualization options
# For more explanation please visit:
bn.line_width = 2.0 # The thickness of edges
bn.text_size = 13 # The fontsize of the text
bn.detail_level = 2 # 0=no text, 1=truncated text, 2=full text
bn.decimal_place = 2

# Display the widget

In [ ]: