Algorithms for Graphical Models (AGM)

Practical 06: Gibbs sampling with BUGS


  1. Introduction
  2. The Asia expert system
  3. 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

  1. Start up WinBUGS by running C:\Program Files(x86)\WinBUGS14\WinBUGS14.exe
  2. 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.
  3. Note that the Asia example contains a number of parts:
  4. Bring up the Specification tool by selecting Specification... from the Model drop-down menu,
  5. 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.
  6. Double click on the word list just under the Data heading. Now select load data from the Specification tool menu. This loads the data.
  7. Now select compile from the Specification Tool.
  8. Double click on the word list just under the Inits heading. Now select load inits from the Specification Tool menu.
  9. 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.
  10. 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.
  11. Go back to the update window, and click update again, to perform another 1000 iterations.
  12. 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.
  13. 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.
  14. 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

  1. This example uses a Bayesian net to analyse data on how many beetles are killed after 5 hour exposure to carbon disulphide.
  2. Open up C:\Program Files(x86)\WinBUGS14\Examples\Beetles.odc from WinBUGS
  3. 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.
  4. 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

Valid XHTML 1.1!