Monte Carlo methods

Level UniversityDifficulty ★★★★★Application⌖ Open in the map

What is it?

Estimate an integral (an expectation) by averaging a function at random points. The error is σ/N\sigma/\sqrt N whatever the dimension, which makes it the only practical method for high-dimensional integrals: rendering, Bayesian statistics, physics, finance.

Why does it exist?

Grid quadrature with nn points per axis needs ndn^d evaluations in dd dimensions — hopeless for the 10-dimensional light paths of a renderer or the million-dimensional posteriors of statistics. Random points do not care about dimension (Ulam and von Neumann, Los Alamos, 1946).

Formulas

∫Ωf(x) dx≈∣Ω∣N∑i=1Nf(xi),εN≈σN\int_\Omega f(x)\,\dd x \approx \frac{|\Omega|}{N}\sum_{i=1}^N f(x_i), \qquad \varepsilon_N \approx \frac{\sigma}{\sqrt N}
∫f(x) dx=𝔼x∼q[f(x)q(x)]\int f(x)\,\dd x = \E_{x\sim q}\Big[\frac{f(x)}{q(x)}\Big]
importance sampling

Why does it matter?

Path tracing in films, risk models in finance, particle transport in reactors and MCMC in Bayesian AI are all Monte Carlo.

The mathematics behind it

  • Definite integral★★★★★fundamental

    Monte Carlo estimates ∫f\int f as an average of ff at random points; error O(N−1/2)O(N^{-1/2}) in any dimension.

  • Grid quadrature in dd dimensions needs ndn^d points; Monte Carlo's O(N−1/2)O(N^{-1/2}) error does not depend on dd.

  • Cumulative distribution function★★★★★fundamental

    Inverse transform sampling: e.g. −ln⁡(1−U)/λ-\ln(1 - U)/\lambda is exponential with rate λ\lambda.

  • Expectation★★★★★fundamental

    Monte Carlo estimates expectations by sample averages.

  • Variance★★★★★fundamental

    MC error is σ/N\sigma/\sqrt N; variance reduction (importance sampling, control variates) is the main lever.

  • Inverse functions★★★★★frequent

    Inverse transform sampling: if UU is uniform on (0,1)(0,1), F−1(U)F^{-1}(U) has distribution FF.

  • Asymptotic notation (O, o, Ω, Θ)★★★★★frequent

    Monte Carlo error is O(N−1/2)O(N^{-1/2}) in any dimension — 100 times more samples for one more digit.

  • Continuous random variables★★★★★frequent

    Monte Carlo methods draw samples of continuous random variables to estimate integrals.

  • Riemann sums★★★★★frequent

    Monte Carlo integration is a Riemann-like sum with random sample points instead of a grid.

  • Integration by substitution★★★★★frequent

    Importance sampling and inverse-transform sampling are changes of variable in the integral being estimated.

Where is it used?

Computing topics reachable from here, through the chain of ideas that leads to them:

What depends on it

This page has the essentials. A fuller treatment (intuition, formal definition, worked example) is on the way.

↑ ↓ to navigate · ↵ · Esc