Skip to content
BIASED

Monte Carlo and Markov chains

Block 1 of 8~3 min

An integral as an average over samples

The topic Variational inference replaced the posterior with the best member of a family qq. That answer is fast but biased: whatever the family cannot represent is simply missing, and nothing in the output says how much. This topic takes the other road. Instead of approximating the posterior by a formula, we draw samples from it and average.

Almost everything we want from a posterior is an expectation. The posterior mean, the probability of a set AA, the posterior predictive:

E[θ∣X],P(θ∈A∣X)=E[1{θ∈A}∣X],p(x∗∣X)=E[p(x∗∣θ)∣X].\mathbb E[\theta \mid X], \qquad P(\theta \in A \mid X) = \mathbb E\big[\mathbb 1\{\theta \in A\} \mid X\big], \qquad p(x^* \mid X) = \mathbb E\big[p(x^* \mid \theta) \mid X\big].

All three have the form I=Epf(x)=∫f(x) p(x) dxI = \mathbb E_p f(x) = \int f(x)\, p(x)\, dx. If x(1),…,x(K)x^{(1)}, \dots, x^{(K)} are independent draws from pp, the Monte Carlo estimate is the sample average:

I^K=1K∑k=1Kf(x(k)).\hat I_K = \frac{1}{K} \sum_{k=1}^{K} f\big(x^{(k)}\big).

It is unbiased, EI^K=I\mathbb E \hat I_K = I, and the law of large numbers gives I^K→I\hat I_K \to I when Ep∣f∣<∞\mathbb E_p \lvert f \rvert < \infty. If also σf2=Var⁡pf(x)<∞\sigma_f^2 = \operatorname{Var}_p f(x) < \infty, then

Var⁡I^K=σf2K,K (I^K−I)→dN(0,σf2).\operatorname{Var} \hat I_K = \frac{\sigma_f^2}{K}, \qquad \sqrt K\, (\hat I_K - I) \xrightarrow{d} \mathcal N(0, \sigma_f^2).

So the typical error is σf/K\sigma_f / \sqrt K. The normal shape is a large-KK statement, not an exact one for every KK.

The running example is the coin from the topic The Bayesian approach: a uniform prior and three heads give the posterior Beta⁡(4,1)\operatorname{Beta}(4, 1) with density p(θ∣X)=4θ3p(\theta \mid X) = 4\theta^3 on [0,1][0, 1]. Its mean is 0.80.8, the probability that the next toss is heads, and its standard deviation is σ≈0.163\sigma \approx 0.163. With K=100K = 100 posterior draws, the average of the θ(k)\theta^{(k)} lands within about 0.0160.016 of 0.80.8.

Two remarks. The rate K−1/2K^{-1/2} contains no dimension: averaging works the same way for a 1000-dimensional θ\theta. But σf\sigma_f, the cost of one draw and, later, how fast a chain mixes can all depend heavily on dimension. And the whole method rests on one assumption we have not earned yet: that we can draw from pp at all. The next three blocks do that in one dimension.

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