Skip to contentScholarGate
LibraryBookshelfDeskReview StudioAssistant
Sign in
On this page
IntuitionHow it worksWhen to use itStrengths & limitationsCommon pitfallsApplicationsFrequently asked🔒 Read the full methodSourcesRelated methods
Cite this pageSpotted an issue on this page? Report or suggest a fix →
Home›Bayesian›Hamiltonian Monte Carlo
Bayesian methods

Hamiltonian Monte Carlo

Hamiltonian Monte Carlo Sampling · Also known as: HMC, Hybrid Monte Carlo, NUTS, No-U-Turn Sampler, gradient-based MCMC

Hamiltonian Monte Carlo (HMC) is a gradient-based Markov chain Monte Carlo algorithm that uses the geometry of the log-posterior surface to make large, informed jumps through parameter space instead of the small random steps of classical MCMC. Originally introduced for lattice field theory by Duane, Kennedy, Pendleton, and Roweth (1987) under the name Hybrid Monte Carlo, and brought into mainstream statistics by Radford Neal's authoritative 2011 chapter, HMC is today the default sampler in Stan and PyMC and is widely regarded as the state-of-the-art engine for Bayesian posterior inference in high-dimensional models.

ScholarGate
  1. Bayesian methods
  2. v1
  3. 3 Sources
  4. PUBLISHED
Cite this page →
Tools & resources
Download slides
Learn & explore

Read the full method

Members only

Sign in with a free account to read this section.

Sign in

Method map

The neighbourhood of related methods — select a node to explore.

Hamiltonian Monte Carlo
Bayesian RegressionMCMCVariational InferenceDynamic Hamiltonian Mont…Dynamic Sequential Monte…Gibbs SamplingHamiltonian Monte Carlo…Hamiltonian Monte Carlo…Hierarchical Hamiltonian…Hierarchical Markov Chai…

+15 more

When to use it

HMC is the preferred sampler when (1) the posterior is continuous and differentiable with respect to all parameters — a necessary condition for gradient computation; (2) the parameter space is moderately to highly dimensional, typically d > 5, where random-walk samplers become geometrically inefficient; and (3) accurate posterior geometry matters, such as when parameters are correlated or the posterior has complex curvature. HMC is unsuitable for discrete parameters (which have no gradient) and requires more computation per proposal than simpler samplers, so it is overkill for low-dimensional or easily-factored posteriors. The No-U-Turn Sampler (NUTS) extension, the default in Stan and PyMC, removes the need to hand-tune the number of leapfrog steps L, making HMC practical without expert tuning.

Strengths & limitations

Strengths
  • Suppresses random-walk behaviour: gradient-guided proposals traverse the posterior in large, informed steps, yielding low autocorrelation and high effective sample size per gradient evaluation.
  • Scales well with dimension: empirical and theoretical results show HMC mixing time grows as O(d^{1/4}) versus O(d) for random-walk Metropolis, making it the method of choice for high-dimensional posteriors.
  • Metropolis correction guarantees exact sampling from the target posterior regardless of step-size errors in the leapfrog integrator.
  • NUTS eliminates manual tuning of the leapfrog trajectory length while preserving the statistical guarantees of HMC.
  • Fully implemented and production-tested in Stan, PyMC, NumPyro, and TensorFlow Probability with rich convergence diagnostics.
Limitations
  • Requires continuous, differentiable log-posteriors; cannot be applied directly to models with discrete latent variables without additional techniques such as marginalisation or embedding.
  • Each leapfrog step requires one gradient evaluation of the full log-posterior, which can be expensive for large datasets without mini-batching (stochastic gradients break detailed balance and require careful correction).
  • Performance is sensitive to the mass matrix M and step size ε; poorly scaled posteriors (e.g. highly correlated or funnel-shaped geometries) require re-parameterisation or adaptation.
  • Warm-up (adaptation) phase can be long for complex geometries, consuming a significant fraction of the total computational budget.

Frequently asked

What is the difference between HMC and the Metropolis–Hastings algorithm?

Both are MCMC algorithms that construct a Markov chain converging to the target posterior, but they differ in how proposals are generated. Metropolis–Hastings uses a simple random-walk proposal centred on the current state, which leads to diffusive exploration and high autocorrelation in high dimensions. HMC uses the gradient of the log-posterior to guide proposals along near-constant-energy trajectories, producing distant, high-probability proposals and much lower autocorrelation. The Metropolis acceptance step in HMC corrects for numerical integration error, so both algorithms share the same theoretical guarantee of exact sampling.

What is NUTS and how does it relate to HMC?

The No-U-Turn Sampler (NUTS), introduced by Hoffman and Gelman (2014), is an adaptive extension of HMC that automatically determines how many leapfrog steps to take by building a binary tree of trajectory segments and stopping when the trajectory starts to double back on itself (the 'U-turn' criterion). This removes the need to manually tune the number of steps L, which is the most sensitive HMC hyperparameter. NUTS is the default sampler in Stan and PyMC and delivers HMC-quality samples without manual trajectory tuning.

What do divergent transitions mean and what should I do about them?

A divergent transition occurs when the leapfrog integrator makes a large numerical error, typically because it enters a region of very high curvature in the posterior — a sign that the step size is too large relative to the local geometry. Divergences are not merely a numerical issue; they indicate that the sampler is not faithfully exploring part of the posterior. The recommended remedy is to re-parameterise the model (e.g. use a non-centred parameterisation for hierarchical models) rather than simply reducing the step size, because the underlying geometric problem will persist.

Can HMC be used with discrete parameters?

Standard HMC requires gradients and therefore cannot be applied directly to discrete parameters. The recommended approach is to marginalise discrete parameters out of the model analytically before sampling, as Stan requires. Alternatively, continuous relaxations or auxiliary variable schemes can embed discrete structure in a differentiable framework. PyMC supports some discrete variables through Gibbs steps mixed with NUTS for the continuous block.

Sources

  1. Duane, S., Kennedy, A. D., Pendleton, B. J., & Roweth, D. (1987). Hybrid Monte Carlo. Physics Letters B, 195(2), 216–222. DOI: 10.1016/0370-2693(87)91197-X ↗
  2. Neal, R. M. (2011). MCMC using Hamiltonian dynamics. In S. Brooks, A. Gelman, G. L. Jones, & X.-L. Meng (Eds.), Handbook of Markov Chain Monte Carlo (pp. 116–162). Chapman and Hall/CRC. ISBN: 978-1420079418 ↗
  3. Gelman, A., Carlin, J. B., Stern, H. S., Dunson, D. B., Vehtari, A., & Rubin, D. B. (2013). Bayesian Data Analysis (3rd ed.). CRC Press. ISBN: 978-1439840955

How to cite this page

ScholarGate. (2026, June 3). Hamiltonian Monte Carlo Sampling. ScholarGate. https://scholargate.app/en/bayesian/hamiltonian-monte-carlo

Related methods

Bayesian RegressionMCMCVariational Inference

Which method?

Set this method beside its closest kin and read them side by side — the library lays the books on the table; the choice is yours.

  • Bayesian RegressionBayesian↔ compare
  • MCMCBayesian↔ compare
  • Variational InferenceBayesian↔ compare
Compare side by side →

Referenced by

Dynamic Hamiltonian Monte CarloDynamic Sequential Monte CarloGibbs SamplingHamiltonian Monte Carlo with Measurement ErrorHamiltonian Monte Carlo with Missing DataHierarchical Hamiltonian Monte CarloHierarchical Markov Chain Monte CarloMCMC for Model ComparisonMCMC with missing dataMetropolis-Hastings AlgorithmMultilevel Gibbs SamplingMultilevel Hamiltonian Monte CarloMultilevel MCMCNo-U-Turn SamplerRobust Hamiltonian Monte CarloRobust Markov chain Monte CarloRobust Particle FilterRobust Sequential Monte CarloSequential Monte CarloSlice SamplingSpatial MCMCTime series MCMC

Similar methods

Dynamic Hamiltonian Monte CarloNo-U-Turn SamplerHierarchical Hamiltonian Monte CarloRobust Hamiltonian Monte CarloHamiltonian Monte Carlo with Missing DataMarkov Chain Monte CarloMultilevel Hamiltonian Monte CarloHamiltonian Monte Carlo with Measurement Error

Related reference concepts

Hamiltonian Monte CarloBayesian Computation and MCMCMarkov Chain Monte CarloMetropolis-Hastings AlgorithmMarkov Chain Monte CarloMonte Carlo Methods

Spotted an issue on this page? Report or suggest a fix →

ScholarGate — Hamiltonian Monte Carlo (Hamiltonian Monte Carlo Sampling). Retrieved 2026-07-21 from https://scholargate.app/en/bayesian/hamiltonian-monte-carlo · Dataset: https://doi.org/10.5281/zenodo.20539026
Quick facts
Family
Bayesian / MCMC
Type
Gradient-based Markov chain Monte Carlo sampler
Originators
Duane, Kennedy, Pendleton & Roweth (1987); popularised for statistics by Neal (2011)
Year
1987
Purpose
Draw samples from high-dimensional posterior distributions efficiently
Inference
MCMC with gradient-guided proposals
Outputs
Posterior samples, posterior means, credible intervals, convergence diagnostics
Software
Stan (default engine), PyMC, NumPyro, TensorFlow Probability
Related methods
Bayesian RegressionMCMCVariational Inference
ScholarGate

A content-first reference library for research methods — what each one is, how it works, and where it comes from.

Open data (CC-BY)

Explore

  • Library
  • Search the library…
  • Browse by field
  • Fields
  • Journey
  • Compare
  • Which method?

Reference

  • Subjects
  • Atlas
  • Glossary
  • Methodology
  • Philosophy

Your tools

  • Bookshelf
  • Desk
  • Chat

Company

  • About
  • Pricing
  • Contact
  • Suggest a method

Entries are compiled from published sources for reference. Verifying the accuracy and suitability of any information for your own use remains your responsibility.

© 2026 ScholarGate · A research-method reference library
  • Privacy
  • Cookies
  • Terms
  • Delete account