# A Small Bayesian Belief Network

## (Tutorial)

This tutuorial shows you how to implement a small Bayesian belief network (Bbn) in HUGIN Runtime. The Bbn you are about to implement is the one modeled in the apple tree example in the basic concepts section. In the next tutuorial, you will extend this Bbn to an influence diagram.

The qualitative representation of our Bbn is shown in figure 1.

Figure 1: Bbn representing the domain of the apple tree problem.

If you want to understand the design of this Bbn, you should read about it in the basic concepts section.

## Constructing a New Bbn

When you choose to start up HUGIN Runtime, the HUGIN window opens. This window contains a menu bar, a tool bar, and a document pane. In the document pane, a new empty network called "unnamed1" is automatically opened in a network window (see figure 2). It starts up in "edit" mode which allow you to start constructing the Bbn immediately (the other main mode is "run" mode which allow you to use the Bbn).

Figure 2: The network window containing a tool bar, a node edit pane, and a network pane.

## Adding Nodes

The first thing we shall do is add the Sick node. This can be done as follows:

- Select the discrete chance tool in the tool bar of the "unnamed1" network window (see figure 3).
- Click somewhere in the network pane (see figure 2).

When you have clicked in the network pane, a node labeled "C1" appears. We want to change this label to "Sick":

- Select the node with the mouse cursor.
- Enter "Node Properties" by pressing the node properties tool (see figure 3).
- Change both the "Name" and the "Label" fields to "Sick".
- Press the "OK" button.

The "Name" is the internal name of the node while "Label" is the label of the node. If no label is specified (as was the case before you changed the label) the label used is the internal name. The internal name can consist of only the letters 'a'-'z' and 'A'-'Z', the digits '0'-'9', and the underscore character '_' while the label can be almost everything.

Figure 3: From left: The discrete chance tool, the node properties tool, and the causal arrow tool.

The Dry and Loses nodes are added the same way. You can add more nodes without having to press the discrete chance tool all the time by holding down the SHIFT key while clicking in the network pane.

Figure 4: The network pane contains the three nodes Sick, Dry, and Loses has been added to the Bbn. The node edit pane contains the cpt of the currently active node.

## Adding Causal Arrows

Now, you should have a Bbn as the one shown in the network pane in figure 4. To add the causal arrows from Sick to Loses and from Dry to Loses, do as follows:

- Press the causal arrow tool (see figure 3).
- Drag an arrow from Sick to Loses with the left mouse button while holding down the SHIFT key.
- Drag an arrow from Dry to Loses with the left mouse button.

What you have by now should be the complete qualitative representation as the one in figure 1. The next step will be to specify the states and the conditional probability table (cpt) of each node.

## The States

In the introduction to Bbns the states of the nodes were specified as follows: Sick has two states: "sick" and "not", Dry has two states: "dry" and "not", and Loses has two states "yes" and "no".

First, we shall tell you how to specify the states of Sick:

- Choose the Sick node as the currently active node by selecting it from the drop down list below the tool bar or simply by double clicking it.
- Press the add state tool in the tool bar (see figure 5).
- Click the field containing the text "State 0" in the cpt in the node edit pane.
- Type the text "sick" in the field to give the state this name.
- Click the field containing the text "State 1" in the cpt.
- Type the text "not" in the field.

Now, do the same with Dry.

Figure 5: The add/delete state tools.

You can do exactly the same with Loses, but you might be a little surprised when selecting Loses as the active node because the cpt of Loses is a little bigger than those of Sick and Dry. This is just because Loses has parent nodes (which Sick and Dry has not).

- Add a state to Loses and name the two states "yes" and "no" (in both the "Name" field and the "Label" field).

## Entering Cpt Values

The next step is to enter the cpt values correctly (as default HUGIN Runtime has given all nodes a uniform distribution). The values were specified in the introduction to Bbns and they are shown in table 1, 2, and 3.

Sick="sick" | Sick="not"
0.1 | 0.9
Table 1: P(Sick).

Dry="dry" | Dry="not"
0.1 | 0.9
Table 2: P(Dry).

| Dry="dry" | Dry="not"
Sick="sick" | Sick="not" | Sick="sick" | Sick="not"
Loses="yes" | 0.95 | 0.85 | 0.90 | 0.02
Loses="no" | 0.05 | 0.15 | 0.10 | 0.98
Table 3: P(Loses | Sick, Dry).

First, enter the values into the Sick node:

- Choose the Sick node as the currently active node.
- Click the field representing Sick="sick".
- Enter the value 0.1 (from table 1).
- Click the field representing Sick="not".
- Enter the value 0.9 (from table 1).

Enter the values of Dry and Loses the same way. When you enter the values into the cpt of the Loses node, be careful to get it done right. When you have entered all cpts, the network window should look like figure 6.

Figure 6: The document window with Loses chosen as currently active node. The cpt of Loses is seen in the node edit pane.

This finishes the construction of the Bbn. At this point it would be a good idea to save the Bbn. Here is how to do it:

- Select "Save As" from the "File" menu.
- Enter a name (e.g. "apple.hkb").
- Press "Save".

## Compiling the Bbn

Now is the time to compile the net and see how it works:

- Press the run mode tool button in the tool bar (see figure 7).

Figure 7: The run mode tool button.

If you have followed the guidance of this tutuorial, there should not be any errors in the compilation process. The compilation should be finished very fast with a small Bbn like ours. After the compilation, the "run" mode is entered (you have so far only been working in "edit" mode).

Running in "run" mode, the network window is split up in two by a vertical separation (see figure 8). To the left is the node list pane and to the right is the network pane.

Figure 8: The network window in "run" mode. To the left is the node list pane (having Loses and Sick expanded) and to the right is the network pane.

You can view the probabilities of a node being in a certain state by expanding the node in the node list pane. You expand a node by double clicking it in the node list pane (if you click on the small node icon in the node list pane, you only need to click it once). Now, expand Loses and Sick:

- Double click Loses in the node list pane.
- Double click Sick in the node list pane.

You can also expand all nodes at once by pressing the expand node list tool in the tool bar just to the right of the node properties tool.

## Is the tree sick?

Now, imagine that you want to use your Bbn to find the probability of an apple tree being sick given the information that the tree is losing its leaves. This is done as follows:

- Expand all nodes (by pressing the expand node list tool).
- Enter the fact that the tree is losing its leaves by double clicking the state "yes" of the Loses node.
- Propagate the Bbn by pressing the sum propagation tool in the tool bar (see figure 9).
- Read the probability of Sick being in state "sick"

Figure 9: The sum propagation tool.

This should give the output shown in figure 10.

Figure 10: Our Bbn after entrance of the evidence that the tree is losing its leaves and sum propagation.

The probability of the tree being sick is now 0.49.

If you do not read the value specified above, you have probably mistyped something when filling in the cpts. Then, check the cpts of all the nodes.

## The Monitor Windows

In the last section, you used the node list pane to enter evidence and retrieve beliefs. You can also do this by using the monitor windows. The monitor windows show the same information as the node list pane but you have the opportunity to place the monitor windows near the corresponding nodes of the Bbn in the network pane. You can open a monitor window for each node in the network pane, but the best way to use them is probably only to open a monitor window for the nodes in the Bbn which have special interest. Else, they might take up too much space.

Now, we shall open monitor windows for Sick and Loses and repeat the calculations from before. First, initialize the Bbn:

- Press the initialize tool button (to the left of the sum propagation tool).

Then, we are ready to open the monitor windows of Sick and loses.

- Select Sick and Loses (hold down the SHIFT key to select more nodes at the same time).
- Choose "Show Monitor Windows" from the "View" menu.

Figure 11: Monitor windows of Sick and loses are now shown in the network pane.

## The most Likely Combination

The rest of this first tutuorial shows some very useful aspects of HUGIN Runtime but they can be skipped. If you want to continue with the second tutuorial showing how to construct a small influence diagram, you have all you need by now.

From the propagation above we could also see that the probability of the tree suffering from drought is 0.47. In both the case of Sick and Dry it is more likely that the state is "not". This could make one believe that the most likely combination of states is when both Sick and Dry is in state "not". However, this is a wrong conclusion. If you want to find the most likely combination of states in all nodes, you should use max propagation (in stead of sum propagation). The max propagation tool is found in the tool bar just to the right of the sum propagation tool.

Now, try to press the max propagation tool. In each node, a state having the value 100.00 belongs to a most likely combination of states. In this case, this gives one unique combination being the most likely: Sick is "sick" and Dry is "not"

We see that even if Sick="sick" is less likely than Sick="not", Sick="sick" is contained in the most likely combination of the states of the nodes while Sick="not" is not. This shows that you need to be careful about your conclusions from the result of a propagation.

Now, one might want to know the probability of this most likely combination of states (or of any other combination of states) under the assumption that the entered evidence holds.

## Calculating the Probability of a Combination of States

Here, we shall describe a technique to calculate the probability of the most likely combination of states given the evidence that the apple tree is losing its leaves. This probability is written:

P(Sick="yes", Dry="not" | Loses="yes")

Any time you perform sum propagation in your Bbn, the probability of the entered evidence is shown in the lower left corner of the HUGIN Runtime window (the P(All) value). If you have chosen the "yes" state of the Loses node and performed sum propagation, you can read the probability of Loses="yes" (written P(Loses="yes")). This value should be 0.1832.

The technique uses the following rule from probability theory (known as the fundamental rule):

P(A, B) = P(A | B) P(B)

The only kind of probabilities we can get from HUGIN is the probability of a series of bits of evidence which can be written in the form:

P(A1, A2,..., An)

We use the fundamental rule to rewrite our requested probability to some expression composed by such components:

P(Sick="yes", Dry="not" | Loses="yes") = P(Sick="sick", Dry="not", Loses="yes") / P(Loses="yes")

In the fundamental rule, we have divided both sides with P(B). Then we have substitutued A with Sick="yes", Dry="not" and B with Loses="yes".

We already know Loses="yes" so we only need to calculate P(Sick="sick", Dry="not", Loses="yes"). This is done as follows:

- Enter Sick="sick", Dry="not", and Loses="yes" in the Bbn.
- Press the sum propagation tool.
- Read P(Sick="sick", Dry="not", Loses="yes") as the P(All) value in the lower left corner.

This value should be 0.081. Now, we are ready to calculate the requested probability:

P(Sick="yes", Dry="not" | Loses="yes") = 0.081 / 0.1832 = 0.442

So, the probability of the most likely combination of states of Sick and Dry is 0.442.

This finishes the first tutuorial. If you want to learn how to construct a small influence diagram, you should go through the second tutuorial.

Back