Monte Carlo demonstrations: Importance sampling, Rejection sampling, Metropolis method, and Slice Sampling

(c) David J.C. MacKay | Lecture course | Book | Other demonstrations |

Overview

This sequence of demonstrations, which takes about an hour to get through if explained in detail, covers all the core Metropolis methods that can be rendered in one dimension.

Requirements

This demonstration should work if you are running X-windows on a unix machine that has octave and gnuplot.
If you have got octave and gnuplot on some other system (eg cygwin under Windoze), it may work.
rejectionsampling

To run the demonstration:

  1. get the demonstration files (41K) by clicking here http / ftp
  2. unpack thus:
           tar zxvf mcmc.tar.gz
    This unpacks a load of files into a directory called mcmc. [If there are any complaints about the clock time use tar zxvfm mcmc.tar.gz]
  3.        cd mcmc
  4. (optional) modify your X windows defaults so that the gnuplot colours and fonts come out right. (Execute this command on the machine running X windows.)
           xrdb -load Xdefaults.gnu
           
  5.  octave
           
    (Works fine with octave-2.0 but not with octave-2.1.33, which seems to have plotting bugs.)
  6. To run the demo:
           load 'DEMO'
           
    Select from a range of demonstrations. If you keep hitting return you will be taken through the sequence
    1. Importance sampling
    2. Rejection sampling
    3. Metropolis method
    4. Slice sampling
    slicesampling by selecting option [14] you can switch between two alternative target densities P*(x); the second one being more wiggly than the first.

Commentary


David MacKay <mackay@mrao.cam.ac.uk>
Last modified: Mon Feb 17 14:53:31 2003