Home▸AI & Machine Learning▸Hamiltonian Monte Carlo (2D): Leapfrog Paths, Samples and Autocorrelation

🌀 Hamiltonian Monte Carlo (2D): Leapfrog Paths, Samples and Autocorrelation

The same live sampler on a flat density map: the leapfrog path, the accept or reject ring, the cloud of samples and the particle, with histograms, autocorrelation and energy error beside it. Compare Hamiltonian Monte Carlo with a random walk on three targets.

AI & Machine Learning2DAdvanced60 FPS📱 Mobile-adapted🟠 Blender⇄ 3D version
Hamiltonian Monte Carlo (2D): Leapfrog Paths, Samples and Autocorrelation ↗ Open standalone

Fitting a Bayesian model means characterising a posterior distribution that almost never has a closed form — so instead you sample from it. This simulator renders that posterior as a real 3D probability-density surface and runs Hamiltonian Monte Carlo on it exactly as Stan or PyMC would: each proposal samples a random momentum, integrates a physical trajectory across the surface with the leapfrog method, and accepts or rejects it by how well total energy was conserved. Watch the chain glide along a correlated ridge far more efficiently than a naive random walk could, tune the step size and trajectory length to see acceptance rate trade off against exploration, and switch to a bimodal target to see where even a gradient-aware sampler can get stuck in one mode.

⚙ Under the hood

The same live sampler on a flat density map: the leapfrog path, the accept or reject ring, the cloud of samples and the particle, with histograms, autocorrelation and energy error beside it. Compare Hamiltonian Monte Carlo with a random walk on three targets.

Hamiltonian Monte CarloMCMCLeapfrog IntegratorBayesian InferenceEffective Sample Size

2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)