ArticleslgStudy

science

Hamiltonian Monte Carlo

Hamiltonian Monte Carlo is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Hamiltonian Monte Carlo rather than just read about it. In short: The Hamiltonian Monte Carlo algorithm (originally known as hybrid Monte Carlo) is a Markov chain Monte Carlo method for obtaining a sequence of random samples whose distribution converges to a target probability distribution that is difficult to sample directly. This sequence can be used to estimate integrals of the target distribution, such as expected values and moments.

Hamiltonian Monte Carlo — main illustration
Hamiltonian Monte Carlo — illustration

Key takeaways

  • Hamiltonian Monte Carlo belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Hamiltonian Monte Carlo to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Hamiltonian Monte Carlo from memory before moving on to harder problems.

Reference excerpt

The Hamiltonian Monte Carlo algorithm (originally known as hybrid Monte Carlo) is a Markov chain Monte Carlo method for obtaining a sequence of random samples whose distribution converges to a target probability distribution that is difficult to sample directly. This sequence can be used to estimate integrals of the target distribution, such as expected values and moments. Hamiltonian Monte Carlo corresponds to an instance of the Metropolis–Hastings algorithm, with a Hamiltonian dynamics evolution simulated using a time-reversible and volume-preserving numerical integrator (typically the leapfrog integrator) to propose a move to a new point in the state space. Compared to using a Gaussian random walk proposal distribution in the Metropolis–Hastings algorithm, Hamiltonian Monte Carlo reduces the correlation between successive sampled states by proposing moves to distant states which maintain a high probability of acceptance due to the approximate energy conserving properties of the simulated Hamiltonian dynamic when using a symplectic integrator. The reduced correlation means fewer Markov chain samples are needed to approximate integrals with respect to the target probability distribution for a given Monte Carlo error. The algorithm was originally proposed by Simon Duane, Anthony Kennedy, Brian Pendleton and Duncan Roweth in 1987 for calculations in lattice quantum chromodynamics. In 1996, Radford M. Neal showed how the method could be used for a broader class of statistical problems, in particular artificial neural networks. But the burden of having to provide the algorithm with gradients of the model graph delayed its wider adoption in statistics and other quantitative disciplines, until in the mid-2010s the developers of Stan implemented HMC in combination with automatic differentiation.

Algorithm Suppose the target distribution to sample is f ( x ) {\displaystyle f(\mathbf {x} )} for x ∈ R d {\displaystyle \mathbf {x} \in \mathbb {R} ^{d}} ( d ≥ 1 {\displaystyle d\geq 1} ) and a chain of samples X 0 , X 1 , X 2 , … {\displaystyle \mathbf {X} _{0},\mathbf {X} _{1},\mathbf {X} _{2},\ldots } is required. Hamilton's equations are

d x i d t = ∂ H ∂ p i and d p i d t = − ∂ H ∂ x i {\displaystyle {\frac {{\text{d}}x_{i}}{{\text{d}}t}}={\frac {\partial H}{\partial p_{i}}}\quad {\text{and}}\quad {\dfrac {{\text{d}}p_{i}}{{\text{d}}t}}=-{\dfrac {\partial H}{\partial x_{i}}}}

where x i {\displaystyle x_{i}} and p i {\displaystyle p_{i}} are the i {\displaystyle i} th component of the position and momentum vector respectively and H {\displaystyle H} is the Hamiltonian. Let M {\displaystyle M} be a mass matrix which is symmetric and positive definite, then the Hamiltonian is

H ( x , p ) = U ( x ) + 1 2 p T M − 1 p {\displaystyle H(\mathbf {x} ,\mathbf {p} )=U(\mathbf {x} )+{\dfrac {1}{2}}\mathbf {p} ^{\text{T}}M^{-1}\mathbf {p} }

where U ( x ) {\displaystyle U(\mathbf {x} )} is the potential energy. The potential energy for a target is given as

U ( x ) = − ln ⁡ f ( x ) {\displaystyle U(\mathbf {x} )=-\ln f(\mathbf {x} )}

… excerpt ends here. Continue reading the full article.

Illustrations

Hamiltonian Monte Carlo: Hamiltonian Monte Carlo sampling a two-dimensional probability distribution
Hamiltonian Monte Carlo sampling a two-dimensional probability distribution

Worked examples

Example 1 — a first encounter with Hamiltonian Monte Carlo

Start with the simplest possible case. Write down what Hamiltonian Monte Carlo claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Hamiltonian Monte Carlo before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Hamiltonian Monte Carlo ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Hamiltonian Monte Carlo

In research
Hamiltonian Monte Carlo appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Hamiltonian Monte Carlo in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Hamiltonian Monte Carlo is common in secondary-school and first-year university syllabi. It links to neighbouring topics Markov chain Monte Carlo, Monte Carlo methods, so understanding it makes those chapters shorter.
In everyday life
Look for Hamiltonian Monte Carlo outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Hamiltonian Monte Carlo” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Hamiltonian Monte Carlo in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Hamiltonian Monte Carlo means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Hamiltonian Monte Carlo out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Hamiltonian Monte Carlo in simple terms?

The Hamiltonian Monte Carlo algorithm (originally known as hybrid Monte Carlo) is a Markov chain Monte Carlo method for obtaining a sequence of random samples whose distribution converges to a target probability distribution that is difficult to sample directly. This sequence can be used to estimat…

Why does Hamiltonian Monte Carlo matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Hamiltonian Monte Carlo?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Hamiltonian Monte Carlo.

Tags

  • Markov chain Monte Carlo
  • Monte Carlo methods

Keep exploring