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
–

Tip: click the plot to restart the chain from that point.

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

Random-walk Metropolis, MALA and Hamiltonian Monte Carlo all rely on the Metropolis–Hastings rule: propose a move from xx to yy and accept it with probability

α(x,y)=min⁡(1, π(y) q(x∣y)π(x) q(y∣x)),\alpha(x, y) = \min\left(1,\ \frac{\pi(y)\, q(x \mid y)}{\pi(x)\, q(y \mid x)}\right),

where π\pi is the target density and qq is the proposal distribution. For more on each sampler, read Four ways to explore a distribution.