An integral as an average
The topic Markov chains ended with the ergodic theorem: the average of along one long run of a chain converges to . 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, . A model's risk is the expected loss over the data distribution. An integral over is an expectation too: for . In general we want
When the integral has no closed form, draw i.i.d. from and average. This is the Monte Carlo estimate:
By linearity, : the estimate is unbiased. By the law of large numbers, whenever . The topic The law of large numbers already used this to estimate from points in a quarter disc. The topic What probability is used it for de Méré's bet: there was the indicator of "at least one six in four rolls", and the share of winning games was .
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.