Algorithms for Graphical Models (AGM)
Practical 06: Gibbs sampling with BUGS
-
Introduction
-
The Asia expert system
-
Beetles
Introduction
This practical asks you to work through a couple of examples
using the WinBUGS tool. To use this tool you should be running
Windows, so if you aren't reboot now!
The WinBUGS stuff is in C:\Program Files(x86)\WinBUGS14. You
can start WinBUGS by running the following: C:\Program
Files(x86)\WinBUGS14\WinBUGS14.exe
The Asia expert system
-
Start up WinBUGS by running C:\Program
Files(x86)\WinBUGS14\WinBUGS14.exe
-
Once WinBUGS has started, use the Open command from
the File menu to open the file C:\Program
Files(x86)\WinBUGS14\Examples\Asia.odc. This contains the
fictitious "Asia" medical expert system, which was previously
discussed in the lectures.
-
Note that the Asia example contains a number of parts:
-
The model: a description of the Asia Bayesian net in the
BUGS language.
-
The data: in this case the data just gives the conditional
and unconditional probabilities needed to define the
Bayesian net.
-
Initial values: BUGS uses simulation (Markov Chain
Monte Carlo) to do its computations. Here someone has
manually put in some initial values for the nodes of the
net. (BUGS can usually work out reasonable initial values
if they are not put in by the user).
-
Results: Here are some results from a previous run. You
are going to create some new results.
-
Bring up the Specification tool by selecting
Specification... from the Model drop-down menu,
-
Select check_model from the Specification
tool. This checks there are no syntax errors in the
model description. You should get a model is syntactically
correct mesage at the bottom of your screen.
-
Double click on the word list just under the
Data heading. Now select load data from
the Specification tool menu. This loads the data.
-
Now select compile from the Specification
Tool.
-
Double click on the word list just under the
Inits heading. Now select load inits
from the Specification Tool menu.
-
Now you are ready to do computation by simulation. Select
Update... from the Model menu. A window
will appear. Don't bother changing the default values you get,
just click the update button to do 1000
iterations. This means 1000 guessed values for each node are
generated. So far you are not acutally recording any of these
1000 guessed values for each node. We are just running the
chain in order to "forget" the initial values. No need to kill
the window.
-
Now select Samples... from the Inference menu. Type
smoking in the node window, and then click
set. From now on guessed values for smoking
will be recorded. Do the same for
lung.cancer.
-
Go back to the update window, and click update again, to
perform another 1000 iterations.
-
Now we will have a look at the values that have been produced
by the simulation you have just run. Select
Samples... again from the Inference window
to get the Sample Monitor Tool window back (no need
to do this, if the window is still there!). Make sure
lung.cancer appears in the node window, by using the
little arrow on the right of the node box, if necessary. Click
on density to get a histogram of the values which
have been generated for lung.cancer. A value of "1"
indicates "no", and "2" indicates "yes". Leave the window open
and do another 1000 updates as before.
-
With lung.cancer in the node window, click on
density again. The histogram won't have changed due
to the last 1000 updates, so we have converged on the correct
values for P(lung.cancer=yes) and
P(lung.cancer=no). Have a look at the histogram for
smoking too.
-
Also click on trace in the Sample Monitor
Tool. with lung.cancer in the node window. This
shows the values of lung.cancer on each
iteration. (It is usually "1" which means "no")
Beetles
-
This example uses a Bayesian net to analyse data on how many
beetles are killed after 5 hour exposure to carbon
disulphide.
-
Open up C:\Program Files(x86)\WinBUGS14\Examples\Beetles.odc
from WinBUGS
-
Now proceed as for the Asia example, this time keeping track
of the node alpha. Note how the graph produced by the
density button gets smoother as you do more iterations. This
is because we are converging to the true probability
distribution for this parameter.
-
Note that alpha can have infinitely many values, it
is a continuous random variable. Most real applications of
Bayesian nets focus on continuous valued random
variables.
Last modified: Tue Nov 21 20:42:49 GMT 2006