The Physics Travel Guide

Monte-Carlo Simulations

Prerequisites: Statistics. Full path (2 pages)

Best explanations

Intuitive

Monte Carlo methods compute quantities by random sampling. A standard first example: draw a square, inscribe a quarter circle, and throw darts at random at the square. The fraction of darts that land inside the quarter circle approaches the ratio of the two areas, which is a quarter of pi. Counting hits gives an estimate of pi, and the estimate improves the more darts we throw.

The same idea works for any average or integral. Instead of evaluating a function on a regular grid of points, we evaluate it at randomly chosen points and take the mean. A grid becomes hopeless in many dimensions: with ten points per axis, a system with 100 variables would need ten to the power 100 grid points. The error of a random estimate shrinks with the number of samples at a rate that does not depend on the number of dimensions. This is why Monte Carlo is the standard tool for problems with very many variables, such as a magnet made of many interacting spins, a gas of many molecules, or a quantum field on a lattice.

In physics we usually need samples from a particular distribution, for example configurations weighted by the Boltzmann factor. Monte Carlo algorithms such as the Metropolis algorithm do this with a random walk through configuration space that visits each configuration with the right frequency, so that averages over the walk become thermal averages.

In Monte-Carlo simulations parameters are chosen randomly and then compared to a predefined goal.

Concrete

Monte Carlo integration. Suppose we want the expectation value of ff under a probability density pp, I=∫f(x) p(x) dx.I = \int f(x)\,p(x)\,dx. Draw NN independent samples x1,…,xNx_1,\dots,x_N from pp and form the sample mean I^N=1N∑i=1Nf(xi).\hat I_N = \frac1N\sum_{i=1}^N f(x_i). Its expectation value is II, and its variance is σf2/N\sigma_f^2/N with σf2=∫(f−I)2p dx\sigma_f^2=\int (f-I)^2p\,dx. The statistical error is therefore σf/N\sigma_f/\sqrt N, independent of the dimension of xx, and σf\sigma_f can itself be estimated from the samples. In the dart example, xx is uniform on the unit square, f=1f=1 inside the quarter circle and 00 outside, so I=π/4I=\pi/4 and σf2=π4(1−π4)\sigma_f^2=\frac\pi4(1-\frac\pi4).

The error can be reduced by importance sampling: draw from a density qq that is large where ∣fp∣|fp| is large, and average f(x)p(x)/q(x)f(x)p(x)/q(x) instead. The mean is unchanged and the variance can be much smaller.

Markov chain Monte Carlo. In statistical mechanics we need averages in the canonical ensemble, ⟨A⟩=1Z∑CA(C) e−βE(C),Z=∑Ce−βE(C),\langle A\rangle = \frac1Z\sum_C A(C)\,e^{-\beta E(C)},\qquad Z=\sum_C e^{-\beta E(C)}, where CC runs over configurations, for example all 2N2^N spin configurations of an Ising model. We cannot sample e−βE/Ze^{-\beta E}/Z directly because ZZ is unknown. The Metropolis algorithm produces a chain of configurations instead:

  1. From the current configuration CC, propose C′C', for example by flipping one randomly chosen spin, with a symmetric proposal probability.
  2. Compute ΔE=E(C′)−E(C)\Delta E = E(C')-E(C).
  3. Accept C′C' with probability min⁡(1,e−βΔE)\min(1,e^{-\beta\Delta E}); otherwise keep CC as the next element of the chain.

Only energy differences enter, so ZZ is never needed. The acceptance rule satisfies detailed balance, e−βE(C)P(C→C′)=e−βE(C′)P(C′→C)e^{-\beta E(C)}P(C\to C') = e^{-\beta E(C')}P(C'\to C), so the Boltzmann distribution is stationary. After discarding an initial equilibration period, ⟨A⟩\langle A\rangle is estimated by the average of AA along the chain. Successive configurations are correlated, so the error is larger than for independent samples, and it has to be estimated with the autocorrelation time or by binning.

In lattice QCD and other lattice field theories, the same method samples field configurations with weight e−SEe^{-S_E}, where SES_E is the Euclidean action obtained after a Wick rotation.

Abstract

Let (Ω,μ)(\Omega,\mu) be a probability space and f∈L2(μ)f\in L^2(\mu). For independent samples Xi∼μX_i\sim\mu, the strong law of large numbers gives I^N=1N∑i=1Nf(Xi)→∫f dμ\hat I_N=\frac1N\sum_{i=1}^Nf(X_i)\to\int f\,d\mu almost surely, and the central limit theorem gives N (I^N−∫f dμ)  →d  N(0,σf2).\sqrt N\,\big(\hat I_N-\textstyle\int f\,d\mu\big)\;\xrightarrow{d}\;\mathcal{N}(0,\sigma_f^2). The rate N−1/2N^{-1/2} is independent of the dimension of Ω\Omega. Deterministic quadrature rules on a grid in dd dimensions converge as N−k/dN^{-k/d} for integrands of smoothness kk, so in high dimension sampling wins. Quasi-Monte Carlo methods replace random points by low-discrepancy sequences and can reach errors close to N−1N^{-1} for sufficiently regular integrands.

Markov chain Monte Carlo constructs a transition kernel P(x,dy)P(x,dy) that leaves the target π\pi invariant, ∫π(dx)P(x,dy)=π(dy)\int\pi(dx)P(x,dy)=\pi(dy). Detailed balance, π(dx)P(x,dy)=π(dy)P(y,dx)\pi(dx)P(x,dy)=\pi(dy)P(y,dx), is a sufficient condition and makes PP self-adjoint on L2(π)L^2(\pi). For a Markov chain on a finite state space that is irreducible and aperiodic, the distribution of XnX_n converges to π\pi from any starting point, and ergodic averages converge to π\pi-expectations; analogous statements hold on general state spaces under Harris recurrence. The Metropolis-Hastings rule turns any proposal kernel q(x,y)q(x,y) into such a chain by accepting with probability α(x,y)=min⁡(1,π(y) q(y,x)π(x) q(x,y)),\alpha(x,y)=\min\left(1,\frac{\pi(y)\,q(y,x)}{\pi(x)\,q(x,y)}\right), which requires π\pi only up to normalization.

For a stationary chain the variance of the ergodic average is Var(I^N)≈2τint σf2N,τint=12+∑t=1∞ρf(t),\mathrm{Var}(\hat I_N)\approx\frac{2\tau_{\mathrm{int}}\,\sigma_f^2}{N},\qquad \tau_{\mathrm{int}}=\frac12+\sum_{t=1}^\infty\rho_f(t), where ρf(t)\rho_f(t) is the normalized autocorrelation of f(Xn)f(X_n) at lag tt, so N/(2τint)N/(2\tau_{\mathrm{int}}) is the effective number of independent samples. The decay of autocorrelations is controlled by the spectral gap of PP. Near a continuous phase transition τint\tau_{\mathrm{int}} grows as a power of the correlation length for local update algorithms (critical slowing down), which motivates nonlocal updates such as cluster algorithms for spin models; lattice gauge theory with dynamical fermions uses hybrid Monte Carlo, which updates all variables at once along molecular dynamics trajectories. All of this assumes a nonnegative weight. When the Boltzmann weight is not positive, as for fermions at finite density or real-time path integrals, the reweighted averages suffer from cancellations that grow exponentially with the volume, the sign problem.

History

Path to this page

  1. Calculus
  2. Statistics