MCMC Sample Program

Release 0.1

 

0) Introduction

1) Getting Started

2) Controls

3) Code

 

gmcmc.m is an illustrative implementation of Markov Chain Monte Carlo sampling methods in Matlab. It was tested in Matlab 7.0.0.27, with Statistics Toolbox 5.0.1. I have not tried it under any other Matlab configurations.

 

It is a simple implementation only meant to illustrate the sampling methods and

allow some basic experimentation. All approaches sample from a bivariate distribution. Feedback is appreciated and welcome, I will try to fix any significant bugs that you find.

 

In this release there are two basic approaches implemented.  The first ("mcmc" in the drop down menu) is a simple metropolis-hastings sampler with a normal proposal distribution.

 

The second is a population mcmc approach based on the work of Warnes, G. "The Normal Kernel Coupler: An adaptive Markov Chain Monte Carlo method for efficiently sampling from multi-modal distributions." Gregory Warnes is easy to locate on the web, and you can go to his site for robust implementation of an mcmc framework.

 

 

1) Getting Started ----------------------

 

To get started download and unzip the matlab files into a directory. Add the directory to Matlab's path. enter gmcmc.m at the prompt.

 

A simple gui for interacting with the code should appear.

 

If you just want to try something quickly.  Press the "Go" button. You will now see the contours of the target distribution. When the status reads "Finished" press the graph button. You will now see the samples chosen overlaid on top of the target distribution.

 

 

2) Controls ----------------------

 

There are several controls that you can experiment with.

 

a) MCMC Method.

 

This is a drop down list of the possible sampling methods that you can use.  In this release there are only two. Currently, each mcmc method requires it's own proposal distribution, and it is not automatically changed by the interface when you change the method. When you change to "mcmc" make sure "proposal2" (or your replacement) is in the Proposal field. When you change to "popmcmc" mak sure "popproposal1" (or your replacement) is in the Proposal field.

 

b) Burn In

 

This is how many samples at the beginning of the run to throw away. The samplers start with uniform distribution, randomly distributed around the 10 by 10 grid. So it will take a little while before the chains will start to sample from the target distribution.

 

c) # of samplers

 

This controls the number of seperate mcmc chains to run concurrently. If the method is "mcmc" the samplers do not interact. If it is "popmcmc" the samplers interact.

 

d) Temperature

 

This does not currently work. But you can use Proposal Sigma to control the bandwidth of the proposal distribution. In the future, you I will allow a series of temperatures to be entered here.

 

e) Distribution

 

This is the target distribution to sample from. There are three options included in the package. targetDistribion[1-3]. You can add your own by simply implementing the same interface, and then entering the name in this box.

 

f) Proposal

 

This is the proposal distribution used by the mcmc chains. Use proposal2 for mcmc, and popproposal1 for popmcmc, or create your own. You can create your own by implementing the same interface as one of the existing files, and then entering it into this field.

 

 

g) Proposal Sigma

 

This controls the bandwidth for the proposal distributions. Initially each proposal distribution uses a normal distribution with a standard deviation specified by Proposal Sigma. 

 

Controls:

 

a) Go

 

This button will run the current mcmc method with the specified parameters and store the results for the graphing functions. It will also display a contour plot of the target distribution in the plot window.

 

b) Clear Graph.

 

This will clear the plot.

 

c) Animate

 

This will animate the path taken by each of the mcmc chains.  Each chain is assigned a different color, and then the movements of each chain are animated.

 

d) Graph

 

This graphs the combined samples from all of the chains.

 

3) Code ----------------------

 

The code is fairly simple and should not be too difficult to follow.

 

mcmc.m and popmcmc.m implement the two sampling methods, and are a good starting point for understanding the layout of the code.

 

There are two key helper methods, the target and the proposal. You can look in samples of each of these to understand the interface (proposal2.m and targetDistribution3). The targetDistribution basically returns the probability density of the target distribution at a given point. The proposalDistribution, given an old state, returns a new state (a,b), and the probability of the transition: qij=P(newState|oldState) and qji=P(oldState|newState)

 

You can send me email if you have questions.

Last modified: 06 Jan 2005