This document provides a comprehensive overview of momentum, its relationship to energy, and how these physical concepts are used in the Hamiltonian Monte Carlo (HMC) algorithm—a powerful tool in Bayesian statistics and machine learning.
In physics, momentum (\(p\)) is defined as mass in motion. It is calculated by multiplying an object’s mass by its velocity:
\[p = m \times v\]
Because velocity includes direction, momentum is a vector quantity—it has both magnitude and direction.
Two factors determine momentum: mass and speed.
In a closed system (no outside forces), the total momentum before a collision equals the total momentum after. Momentum is never created or destroyed—it is only transferred between objects.
Example: When a moving pool ball hits a stationary one, the first slows down (loses momentum) and the second speeds up (gains exactly that momentum). The total remains constant.
In daily life, “momentum” describes the strength of a continuing movement:
For a simple mechanical system with mass \(m\), the Hamiltonian (total energy) is:
\[H(q,p) = U(q) + \frac{p^2}{2m}\]
Where:
In this equation, \(p^2\) simply means \(p \times p\). It appears because:
\[KE = \frac{1}{2}mv^2 = \frac{1}{2}m\left(\frac{p}{m}\right)^2 = \frac{p^2}{2m}\]
By writing kinetic energy this way, we remove velocity and treat position (\(q\)) and momentum (\(p\)) as independent variables—the foundation of Hamiltonian mechanics.
Hamiltonian Monte Carlo (HMC) is a sampling algorithm used in Bayesian statistics. It borrows physics concepts to efficiently explore probability distributions.
| Physics | Statistics |
|---|---|
| Position (\(q\)) | Parameter to estimate (e.g., population mean) |
| Momentum (\(p\)) | Auxiliary variable (randomly sampled) |
| Potential energy (\(U(q)\)) | Negative log-posterior: \(-\log(\text{Posterior})\) |
| Kinetic energy (\(\frac{p^2}{2m}\)) | Drives exploration of the parameter space |
Inject Random Momentum: At each step, randomly sample \(p\) from a normal distribution. The probability of picking \(p\) is proportional to \(e^{-p^2/2m}\) — a Gaussian (bell curve).
Simulate Motion: Use Hamilton’s equations to move the particle across the \(U(q)\) landscape for a fixed time. The kinetic energy \(\frac{p^2}{2m}\) gives it inertia to keep moving in good directions.
Accept/Reject: Because numerical simulation has errors, check if total energy \(H(q,p)\) was conserved. If yes, accept the new sample; if not, reject it.
After simulation, the acceptance probability is:
\[\text{Acceptance} = \min(1, e^{-\Delta H})\]
If the simulation is perfect, \(\Delta H = 0\) and acceptance is 100%—the holy grail of sampling!
This is the critical link between physics and statistics.
In physics, the probability of a state with energy \(E\) is:
\[P(\text{state}) \propto e^{-E}\]
Set \(E = H(q,p) = U(q) + \frac{p^2}{2m}\):
\[P(q,p) \propto e^{-U(q)} \times e^{-p^2/2m}\]
The probabilities separate! The probability of position \(q\) is:
\[P(q) \propto e^{-U(q)}\]
Take logs:
\[\log(P(q)) = -U(q) \implies U(q) = -\log(P(q))\]
\[\text{Posterior} \propto \text{Likelihood} \times \text{Prior}\]
So:
\[U(q) = -\log(\text{Likelihood}) - \log(\text{Prior})\]
The particle rolls downhill to high-probability regions (valleys) and rarely climbs up to low-probability regions (mountains). By sampling from this landscape, HMC generates a histogram of \(q\) values that matches the true posterior distribution.