NEWS 

Building a Bayesian Network

(Tutorial)
This tutorial shows you how to implement a small Bayesian network (BN) in the Hugin GUI. The BN you are about to implement is the one modeled in the apple tree example in the basic concepts section . In the next tutorial, you will extend this BN to an influence diagram.

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

apple_bn
Figure 1: BN representing the
domain of the apple tree problem. 


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

Constructing a New BN
When you start up the Hugin GUI, the edit 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 allows you to start constructing the BN immediately (the other main mode is "run" mode which allows you to use the BN).

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


Adding Nodes
The first thing we will 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 anything.

3knap

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. When you have chosen a node in the network pane, you can access the node properties tool by holding down the right mouse button.

show_nodes
Figure 4: The network pane contains the three nodes Sick, Dry, and Loses that have been
added to the BN. The node edit pane contains the CPT of the currently active node. 


Adding Causal Arrows
Now, you should have a BN similar to 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. The SHIFT key ensures that you can add more arrows without having to press the causal arrow tool again
  • Drag an arrow from Dry to Loses with the left mouse button

What you have by now should be the complete qualitative representation which is similar to 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 BNs 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.

tool_states

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 have not).

  • Add a state to Loses and name the two states "yes" and "no".

Entering CPT Values
The next step is to enter the CPT values correctly (as default the Hugin GUI has given all nodes a uniform distribution). The values were specified in the introduction to BNs 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.

show_states
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 BN. At this point it would be a good idea to save the BN. Here is how to do it:

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

Now we have finished constructing the Hugin knowledge base using Bayesian network technology. Now we want to compile and run the Hugin knowledge base and see if it is behaving correctly.

Continue >>

Hugin Expert A/S · Gasværksvej 5 · DK·9000 Aalborg · Denmark · Phone +45 9655 0790 · Fax +45 9655 0799 · info@hugin.com
© Copyright 2004 · All rights reserved · Copyright Policy