(Tutorial)
This tutorial shows you how the table generator
functionality can be used to simplify how tables are specified for
discrete chance nodes.
Imagine you are playing a game of dice where
you roll a number of dice ranging from 1 to 5. The more sixes you
roll the better, so you are very interested in predicting how many
sixes you can expect to roll.
A very simple Bayesian network can model your
situation. Figure 1 shows a Bayesian network where the number of
the dice rolled (nDice) has an impact on the number of sixes rolled
(nSixes).
 |
Figure
1: BN modelling
the dice problem |
nDice has states:
1, 2, 3, 4, 5 (the number of dice you could be asked to roll).
nSixes has states: 0, 1, 2, 3, 4, 5 (one more than nDice since it
is possible not to roll any sixes).
Now, because we want the states of the nodes to
represent numeric values, we change their type to
"Numbered". Here is shown how to change nDice to a
numbered node:
- Select nDice with the mouse cursor
- Select the "Node Properties"
item of the "Edit" menu
- Select the "Node" tab (if it
is not already selected)
- From the "Type" drop down box
select "Numbered"
- Click "OK"
Now, change
nSixes to be numbered too!
You can edit the number of states and the state
values in the left most column of the node edit pane (as you
probably did in the
first tutorial ). However, you
can also do it through the Node Properties dialog:
- Select nDice with the mouse cursor
- Select the "Node Properties"
item of the "Edit" menu
- Select the "States" tab
- Click the first state (the only state
if you haven't added any states) in the states list
- Start typing "1" - this
should transfer focus to the edit box below the states list
- Press the "Rename" button in
the button list on the right
- Click in the edit box and type
"2"
- Press the "Add After"
button
- Continue entering the state values
(now, pressing the enter key after typing a state value should
automatically use the "Add After" button since this was
the last one activated in the button list)
- After typing all states, press
"OK"
Now, do the same
for nSixes (remember to start with state "0").
Figure 2 shows the Node Properties dialog after
having entered the state values of nDice.
 |
| Figure
2: Entering the state values of nDice |
The conditional
probability table of nSixes in the node edit pane should now look
as the one shown in figure 3.
 |
| Figure
3: The conditional probability table of nSixes |
This table is
rather big and if you should fill it in yourself it would be a
pretty hard task. You would also have a tool for calculating the
Binomial distribution, since the probability of rolling a specific
number of is a Binomial distribution depending on the number of
dice you roll.
However, the Hugin GUI allows you to generate
the table automatically from an expression you specify. To do this
for the nSixes node follow these steps:
- Select nSixes as the currently selected
node (so that it appears in the node edit pane)
- From the "Table" menu select
"Expressions" (notice, that the look of the table
changes dramatically - only one cell is now shown)
- Click in the single field of the table
of nSixes
- From the "Table" menu select
"Build Expression". This should open the
"Expression Builder" dialog
- In the "Function Category"
list select "Discrete Distributions" and in the
"Function Name" list choose "Binomial", then
press "OK". This should close the first dialog of the
expression builder and open another one prompting you for the
arguments to the Binomial distribution
- Click inside the edit box of the
"n" argument
- Select nDice in the "Parents"
list in the bottom and press "Insert"
- In the edit box of the "p"
argument type "1/6"
- Press "OK"
Now, you should have the expression
"Binomial (nDice, 1/6)" in the single field of the nSixes
table. This is shown in figure 4.
 |
Figure
4: The expression table of nSixes after
having specified a Binomial distribution
depending
on nDice |
This ends the
tutorial of building a small Bayesian network using the table
generator. Try compiling it and play with it (try selecting
different values for the nDice node and propagate. After having
compiled the network, you can also go back to edit mode and take a
look at the generated table: Select the nSixes node and from the
"Table" menu select "Manual". You will be
warned that you are destroying the expression, but that does not
matter now. You can rebuild them if you want.