chi-feng/mcmc-demo

Interactive Markov-chain Monte Carlo Javascript demos

What this is

The Markov-chain Monte Carlo Interactive Gallery is a web-based demo that lets you see how different MCMC sampling algorithms behave, and tweak their parameters live in your browser.

What it does

Each algorithm has its own clickable demo page. You can change algorithm parameters on-the-fly and watch how the sampler moves through a target distribution. The demos include visualizations of accepted/rejected proposals, sample trajectories, and the underlying density.

Algorithms covered

Standard MCMC methods:

  • Random Walk Metropolis Hastings
  • Adaptive Metropolis Hastings (Haario et al., 2001)
  • Hamiltonian Monte Carlo (Hoffman & Gelman, 2011)
  • No-U-Turn Sampler (Hoffman & Gelman, 2011)
  • Metropolis-adjusted Langevin Algorithm, MALA (Roberts & Tweedie, 1996)
  • Hessian-Hamiltonian Monte Carlo, H2MC (Li et al., 2015)
  • Gibbs Sampling
  • DE-MCMC-Z (ter Braak & Vrugt, 2008)
  • Microcanonical Hamiltonian Monte Carlo, MCHMC (Robnik et al., 2022)

Non-Markovian iterative sampling method:

  • Stein Variational Gradient Descent, SVGD (Liu et al., 2016)

How to run locally

  1. Clone or download the repository.
  2. Open index.html in a web browser.
  3. No build step — all dependencies ship inside the lib/ folder.

How to add a new algorithm

  1. Copy an existing algorithm from the algorithms directory (the README suggests starting from algorithms/HamiltonianMC.js).
  2. Add your algorithm's JavaScript file to the bottom of app.html — this automatically adds it to the dropdown menu.
  3. Add any new visualizations to Visualizer.prototype.dequeue in main/Visualizer.js. The MCMC simulation pushes visualization events onto an animation queue; most common events (like accepting or rejecting a proposal) already exist. The renderer composites three offscreen canvases: densityCanvas, samplesCanvas, and overlayCanvas.
  4. Add a link to your algorithm in both README.md and index.html.

References

All algorithms link to the papers they're based on, listed in the README (see the numbered list). The papers cover the original adaptive Metropolis method, Hamiltonian Monte Carlo / NUTS, MALA convergence, Hessian-Hamiltonian dynamics, SVGD, differential evolution MCMC, and microcanonical HMC.

Related project

The author also maintains an interactive Gaussian process regression demo at https://github.com/chi-feng/gp-demo.

Related

  • Project
  • Project
  • Project
  • Project