Bayesian Networks Basics Using SamIam

Bayesian Networks are a compact graphical representation of how random variables depend on each other. It can be used to demonstrate the probability of one variable occurring depending on which related variables have been observed. Manual computations of conditional probabilities can be difficult especially when the graph becomes complex. Good thing we have simulation tools that has a graphical interface so we can easily manage the relationships of the variables and compute resulting probabilities.

In this article we will be using Sensitivity Analysis, Modeling, Inference, and More (SamIam) developed by the Automated Reasoning Group from the University of California Los Angeles. It allows us to visually construct our network and easily fill out the conditional probability tables.

Installation

To install SamIam, you need to have the following:

Download and Install the appropriate version of Java for your computer. To check if Java has been installed properly, open Command Prompt and type the command:

java -version

Next, download and unzip, SamIam classic. Inside the folder you will see a Window Batch File named samiam. Double click the file to run SamIam

SamIam files

SamIam should open and you should see the editor window.

Creating Your First Bayesian Network

For this example, we would model the Monty Hall example which goes as follows:

In a gameshow, there are three doors, and behind only one of those doors is a prize. The guest picks the door that they think will lead to the prize. The host (Monty), knowing the location of the prize, will open one of the two remaining doors. This door will always be empty. The host will then ask the guest if they want to change their door or stick with their initial choice. What is the probability that the guest picked the correct door?

  • In the Menu Bar, click File > New. This opens a new Network file in Edit Mode.
  • To add a node click Edit > Add Node, or use the Add Node button on the tool bar, then click on any empty area of the editor. For this example we will create a Guest, Prize, and Monty (Host) node.
  • To add an edge, click Edit > Add Edge or use the Add Edge tool on the tool bar, then click on the parent node, then the child node. Add an edge from Guest -> Monty, then from Prize -> Monty.

You can drag and drop nodes around the work area to make your graph clearer.

Double click a node to edit its properties. The properties tab show which values your random variable can take. You can add more rows. The probabilities tab is where you input the probability table. If your node has no parent, then you will just decide the probability of each outcome. If the node has one or more parents, then you will need to fill up the conditional probability table for all combination of events.

For both the Guest, and Prize nodes, it is an equal 1 out of 3 chance. Put 0.33333 as the probability of each event. Click the Normalize button.

For the Monty node, refer to the following table:

Prize LocationGuest SelectionMonty Opens
= A
Monty Opens
= B
Monty Opens
= C
AA00.50.5
AB001
AC010
BA001
BB0.500.5
BC100
CA010
CB100
CC0.50.50

If the guest, picks the door with the prize, Monty will randomly open either remaining door. If the guest picks an empty door, Monty will surely open the remaining empty door.

SamIam properties window

Simulation

To simulate your network, go to Mode > Query Mode. The background of the work area changes. Right click a node and select Monitor to show the interactive controls. You can drag and drop these controls for better visibility.

To simulate the “observation” of an event, click on one of the options on the monitor. It should turn from green to red and the other monitors will reflect computed values. Click the red option on the monitor to revert back to unobserved.

If you set the Guest selection as Door A, and Monty’s selection as Door B, the probability that the prize is at door A is only 33.33% and not 50%. It is twice as likely that the prize is behind the remaining door.

Monty Hall Problem

Click File > Save to save your work. SamIam supports different file formats including .hugin and .net among others. You can close the program by clicking the top right close button.

With that, you have successfully installed SamIam and simulated a simple example. Next, you can try to simulate a more complex example and try conditioning different combinations of nodes to see how it affects other nodes. 

For additional help in using the tool, consult the SamIam User Documention. If you are interested in simulating this problem using Python, check out this blog post.

 

Address
Quezon City, PH

Work Hours
M-F  07:00-16:00