MCMC Playground
Watch Markov chain Monte Carlo samplers explore a probability distribution, one step at a time.
Trace of the last 400 steps: horizontal coordinatevertical coordinate
- Steps
- 0
- Recent acceptance
- –
- Sample mean
- –
- True mean
- –
- Divergences
- –
How to use it
Pick a target distribution and a sampler, then press Run. The shading shows where the distribution puts its probability, and the dots show where the chain has been. Change the step size while it runs and watch the acceptance rate respond, or click anywhere on the plot to restart the chain from that point.
What to look for
- Correlated Gaussian: random-walk Metropolis and Gibbs take tiny steps along the ridge, while Hamiltonian Monte Carlo covers it in a few moves.
- Two modes: almost every sampler stays in the peak where it starts, so the sample mean ends up far from the true mean.
- Neal’s funnel: no single step size works everywhere. Choose Hamiltonian Monte Carlo, raise the step size, and watch divergences, drawn as red circles, pile up in the narrow neck.
Random-walk Metropolis, MALA and Hamiltonian Monte Carlo all rely on the Metropolis–Hastings rule: propose a move from to and accept it with probability
where is the target density and is the proposal distribution. For more on each sampler, read Four ways to explore a distribution.