Skip to content
BIASED

Monte Carlo methods

Block 1 of 8~2 min

An integral as an average

The topic Markov chains ended with the ergodic theorem: the average of f(Xt)f(X_t) along one long run of a chain converges to Eπf\mathbb E_\pi f. Read backwards, it is a way to compute an expectation by simulation. This topic does the plain version first, with independent samples, and asks the question every simulation must answer: how wrong is the result?

Almost every number we want from a model is an expectation. A probability is the expectation of an indicator, P(A)=E[1A]P(A) = \mathbb E[\mathbb 1_A]. A model's risk is the expected loss over the data distribution. An integral over [0,1][0, 1] is an expectation too: ∫01g(x) dx=E[g(U)]\int_0^1 g(x)\, dx = \mathbb E[g(U)] for U∼U(0,1)U \sim U(0, 1). In general we want

I=E[g(X)]=∫g(x) p(x) dx.I = \mathbb E[g(X)] = \int g(x)\, p(x)\, dx .

When the integral has no closed form, draw X1,…,XnX_1, \dots, X_n i.i.d. from pp and average. This is the Monte Carlo estimate:

I^n=1n∑i=1ng(Xi).\hat I_n = \frac1n \sum_{i=1}^n g(X_i) .

By linearity, E[I^n]=I\mathbb E[\hat I_n] = I: the estimate is unbiased. By the law of large numbers, I^n→I\hat I_n \to I whenever E∣g(X)∣<∞\mathbb E\lvert g(X) \rvert < \infty. The topic The law of large numbers already used this to estimate π\pi from points in a quarter disc. The topic What probability is used it for de Méré's bet: there gg was the indicator of "at least one six in four rolls", and the share of winning games was I^n\hat I_n.

Machine learning runs on such averages. A minibatch gradient estimates the full gradient. The test error of a classifier estimates its risk. A VAE estimates its training objective from a few sampled latent codes (see Generative Models). Each of them is a Monte Carlo estimate, and each inherits its error from the next block.

Answers are saved on the server and tied to this browser until you sign in.