MLSS 2009, MCMC practical

This page contains the practical that went with my tutorial lectures on Markov chain Monte Carlo (MCMC) at the Machine Learning Summer School (MLSS) in Cambridge, 2009.

You can download a .zip archive of all of the files on this webpage. As noted below, I suggest that you do not look at inference.m until you have seriously attempted to get the samplers running on the parameter posterior yourself.

Electronic copy of the handout



Here is the data in two alternative file formats: astro_data.mat, astro_data.txt.

Code for samplers

Here are simple implementations of dumb Metropolis and slice sampling.

slice_sample.m, dumb_metropolis.m.

If you prefer, the Matlab’s statistics toolbox now comes with mhsample and slicesample, although as part of a separate toolbox they will not always be available.

There is a suggestion in the handout for a third sampler if you would like to implement your own.

Code for this problem

I have written code for the joint probability in equation (6) up to a constant: log_pstar.m. I recommend you use this function and the above MCMC samplers to investigate how well you can sample the posterior over parameters.

If you are struggling

Some example “glue” that will drive the sampler on the model’s posterior is: inference.m. I recommend that you don't look at this until you have thought about how to do this yourself. I’ve provided this code so that if you are getting nowhere you can move on by modifying the example and still try out the different samplers.

inference.m calls errorbar_str.m, but only for trivial display purposes.