LLGA · Course notes

Probability Theory for ML: Applications to Monte Carlo Methods and Generative Models

APM_51056_EP · Year 1 · Period 1

Contents

Introduction and overview

Module Probability Theory for ML: Applications to Monte Carlo Methods and Generative Models — official title of the SynapseS 2026-2027 sheet: “Programme d’approfondissement — Théorie des probabilités pour le ML : applications aux méthodes de Monte Carlo et aux modèles génératifs” (occurrence: “Probability theory for ML… - X3A ME2”)
Code APM_51056_EP
Team and workload Course coordinator: Alain Durmus (École Polytechnique) · 36 h in person in the 2026-2027 catalog (official teaching methods: 9 lectures of 2 h + 9 exercise sessions of 2 h, some of them on laptop to implement the simulation algorithms in Python) · enrollment 1–120 · 5 ECTS for the degrees listed on the sheet; language of the occurrence: French · from measure theory to Markov chains: the probabilistic foundation of Monte Carlo methods, MCMC, and generative models based on Langevin dynamics.
Status in the program Notes kept for reference M1 · S1 / period 1 (fall semester, from 17/09/26 to 18/12/26) Not in the LLGA 2026–2027 list: the MScT-LLGA-GD1A track page (read on 22 October 2026) does not include this course unit in LLGA 1 – S1; it is still taught at the École in other tracks, and these notes are kept for reference.

Audience: an engineer who has already drawn Gaussians and estimated a mean by sample average — no need to open on sigma-algebras.

Empirical first: a Monte Carlo estimator that is too noisy, a Metropolis chain that will not mix, a sampler that “works” in dim 2 and dies in dim 100. Only then do we name measure, Markov, Langevin.

Intractable expectations, complex laws, plausible data: from measure to Markov chains, Monte Carlo, MCMC, Langevin. Behind diffusion / score models: samplers and stochastic dynamics. This is the program’s mathematical depth on the randomness side.

What you will be able to do

Official objectives and syllabus (2026-2027 catalog)

Official objectives (paraphrased from the description published on SynapseS): the course sets itself three objectives.

First, present the foundations of probability on the basis of abstract measure theory: construction of probability spaces, of probabilities on measured spaces and of integration over abstract spaces, with the essential properties of the integral.

Next, present and analyze Monte Carlo methods and their “Markov chain” version (MCMC). Finally, conclude with a brief introduction to generative models.

By the end of the course, a student can:

Official syllabus “Plan for the Course” (9 lectures) and mapping to our chapters:

Official theme (SynapseS 2026-2027) Course section that covers it
Lectures 1–2: foundations of integration and measure theory, applied to statistics ch. 0 (review) and ch. 1 (measure and integration, Tonelli-Fubini)
Lectures 3–4: Monte Carlo methods ch. 3 (simulating: inverse, rejection, Box-Muller), ch. 4 (Monte Carlo and variance reduction), ch. 5 (importance sampling)
Lectures 5–6: conditional distributions and stochastic processes ch. 2 (convergence: LLN, CLT, delta method), ch. 6 (conditional expectation), ch. 7 (Markov chains)
Lectures 7–8: Markov chains and MCMC ch. 7 (stationarity, reversibility, ergodicity) and ch. 8 (Metropolis-Hastings, Gibbs, diagnostics, annealing)
Lecture 9: introduction to generative models ch. 9 (Langevin dynamics and generative models)

All official themes are covered. Two chapters go beyond the official syllabus: ch. 9 treats Langevin dynamics in much more depth than the announced “brief introduction”, and ch. 10 (research of the course coordinator: sampling in high dimension) is an addition of these notes, as is the emphasis on MCMC diagnostics and simulated annealing in ch. 8.

Official field Published value (SynapseS 2026-2027)
Field Applied Mathematics (programme d’approfondissement); listed degrees: X, exchange programs, non-degree, M1 MJH; the LLGA 2026–2027 track lists do not include this course unit (see the status row)
Workload 36 h in person · enrollment 1–120
Period / language Fall semester, period 1 (17/09/26 – 18/12/26) · French
Prerequisites Description: undergraduate level in statistics, probability, linear algebra and calculus · “Prerequisites” tab: for X students, at least one course among MAP432, MAP433; for exchange students: APM_41033_EP
Teaching methods 9 lectures of 2 h + 9 exercise sessions of 2 h, some of them on laptop to implement the simulation algorithms; code in Python, no Python prerequisite required (mini-training, tutorial and demonstrations provided at the beginning of the course); examples of industrial applications during lectures
Assessment Exam and Lab · numerical grade out of 20 · resit allowed (max of the two grades) · course unit acquired if final grade ≥ 10 · the grade counts toward the GPA · 5 ECTS for the degrees listed on the sheet (no LLGA value: the track does not list this unit)

Where this course fits in the program

Notes kept for reference: this course unit is not in the LLGA 2026–2027 lists (it is still scheduled in Period 1 for other tracks of the École, 36 h), so no LLGA module requires it. For an LLGA student it is a mathematical deepening rather than an application course.

The official description requires an undergraduate-level background in statistics, probability, linear algebra and calculus; for students of the X engineering cycle, the sheet additionally requires having taken at least one course among MAP432, MAP433.

In the master’s program, its natural prerequisite is the Refresher in Statistics module, whose measure theory, random variables and convergence it takes up to raise them to the level required by simulation: the review chapter ensures the transition.

No Python prerequisite is required: the official sheet specifies that a mini-training and a tutorial are provided at the beginning of the course.

Three LLGA modules use material from these notes; none of them assumes the course.

Computational Optimal Transport for ML and Fairness defines the Wasserstein distance (its ch. 2) in which Theorem 9.5 measures the error of ULA, and studies the sampling error of empirical measures (its ch. 4); Multimodal Generative AI learns, in its ch. 3, the scores that our ch. 9 samples with Langevin dynamics; Reinforcement Learning and Autonomous Agents builds on Markov chains and sampling (Monte Carlo methods for control and evaluation).

For students aiming at a PhD in applied probability or in generative modeling, these notes are a strong mathematical complement to the Year 1 courses.

Course outline

Session plan

36 h in class = 9 lectures of 2 h + 9 exercise sessions of 2 h. The volume and its split are those of the SynapseS 2026–2027 sheet (official teaching methods: 9 lectures of 2 h and 9 exercise sessions of 2 h, some of them on laptop); the sheet gives the theme of each lecture but no chapter-level programme, so the assignment of chapters below is our proposal.

Each row is one week: a 2 h lecture followed by its 2 h exercise session.

Level 1 = foundations (reviews, definitions, first worked examples), 2 = core methods (Monte Carlo, conditioning, Markov chains, MCMC), 3 = advanced material (Langevin dynamics and its link with generative models); the level never goes down from one week to the next.

Session Hours Level Content Practice
1 4 h 1 ch. 0 Review: probability spaces, Markov and Chebyshev; ch. 1 Lebesgue integral, monotone convergence, Tonelli-Fubini Ex. 1
2 4 h 1 ch. 2 Modes of convergence, law of large numbers, CLT, delta method lab: CLT and confidence intervals by simulation
3 4 h 1 ch. 3 Simulating: inverse transform, rejection, Box-Muller Ex. 3
4 4 h 2 ch. 4 Monte Carlo estimator, error bars, antithetic variables, control variates lab: estimating \pi and \ln 2 with variance reduction
5 4 h 2 ch. 5 Importance sampling, weight degeneracy, rare events Ex. 4, 8
6 4 h 2 ch. 6 Conditional expectation: definition, tower property, total variance Ex. 6
7 4 h 2 ch. 7 Markov chains: invariance, reversibility, ergodic theorem Ex. 2
8 4 h 2 ch. 8 Metropolis-Hastings, Gibbs, diagnostics, simulated annealing Ex. 7; lab: random-walk MH on a bimodal target
9 4 h 3 ch. 9 Langevin diffusion, ULA and MALA, the score and generative models Ex. 5

Self-study, outside the 36 h (about 3 h in total): ch. 10 Research (Durmus) — three papers on the non-asymptotic analysis of Langevin algorithms (≈ 3 h).

How to study this module

independent note Score models, diffusion, multimodal: mostly high-dimensional sampling. This module gives the keys (measure → MCMC → Langevin) that research and deployed systems depend on — best read with a diverging estimator in front of you, not only a proof.

0. Review: measure, random variables, convergence

Every chapter of this module computes, bounds or estimates an expectation, so it needs a precise notion of probability space, random variable and distribution, together with two elementary inequalities. This review fixes this vocabulary at the level used in the proofs.

L3 review material used

  • Probability spaces: sigma-algebra, probability measure, random variables, pushforward distribution — the vocabulary of the Refresher Statistics module, chapter 1; if this vocabulary is shaky, now is the time to consolidate it;
  • Standard distributions: binomial, Poisson, exponential, Gaussian, gamma — densities, expectations, variances (see the Refresher Statistics module, chapter 3); independence and product measures;
  • Elementary inequalities: Markov, Chebyshev; “workhorse” laws of large numbers and central limit theorem (see the Refresher Statistics module, chapter 4);
  • Real analysis: numerical series, monotone convergence, power series (expansions of e^x, \cos, \sin), integration by parts, multivariate differential calculus (Jacobian).

Definition 0.1 — Sigma-algebra, measure, probability space A measurable space is a set \Omega equipped with a sigma-algebra \mathcal{F} \subseteq 2^\Omega (it contains \Omega and is stable under complement and countable union).

A probability \mathbb{P} is a measure on (\Omega, \mathcal{F}) with total mass 1: \mathbb{P}(\Omega)=1, countably additive.

A random variable (r.v.) is a measurable map X : \Omega \to \mathbb{R} (the preimage of a Borel set lies in \mathcal{F}); its distribution is the pushforward measure \mathbb{P}_X = \mathbb{P} \circ X^{-1}. This viewpoint — the distribution as a pushforward — is the one that generalizes painlessly to the function spaces of machine learning.

Proposition 0.2 — Markov and Chebyshev (proved) Let X be a real r.v.

  • Markov: if X \geq 0 and a > 0, \mathbb{P}(X \geq a) \leq \mathbb{E}[X]/a;
  • Chebyshev: if \mathrm{Var}(X) < \infty and t > 0, \mathbb{P}\big(|X - \mathbb{E}X| \geq t\big) \leq \frac{\mathrm{Var}(X)}{t^2}.

Proof. Markov: \mathbb{E}[X] \geq \mathbb{E}[X\,\mathbf{1}_{X \geq a}] \geq a\,\mathbb{P}(X \geq a).

Chebyshev: apply Markov to (X - \mathbb{E}X)^2 at level t^2.∎

Why this module All of probabilistic machine learning — VAEs, diffusion, Bayesian inference, stochastic training — rests on three operations: computing expectations (integration), conditioning (conditional expectation), and sampling (simulation, Monte Carlo, MCMC). This module builds these three pillars under minimal assumptions, then connects them to modern generative algorithms (see the Multimodal GenAI module, chapter 3, for the diffusion part). It completes the “recipe” treatment of the Machine Learning module, chapter 7 (EM), by providing the foundations.

1. Measure and integration: expectation, Tonelli-Fubini

Concrete scene: you estimate \mathbb{E}[f(X)] by the sample mean of N=10^4 draws. In dim 1 it converges; in dim 50 almost all points fall outside the useful region and the estimator freezes. This is not a Python bug: it is high-dimensional integration.

This chapter builds expectation properly (Lebesgue, Tonelli-Fubini) so you know when you may swap limit and integral — the reflex before Monte Carlo / MCMC.

What breaks Three classic failures: swapping \int and \sum without checking positivity or integrability (Tonelli/Fubini), believing that a sample mean “always converges quickly” in high dimension, and coding an importance sampler with a proposal that is too narrow. All three sabotage a generative pipeline as badly as a simulation lab.

Definition 1.1 — Construction of the Lebesgue integral Let X \geq 0 be measurable on (\Omega,\mathcal{F},\mathbb{P}). We set \mathbb{E}[X] = \sup\Big\{ \textstyle\sum_{i=1}^{n} a_i\, \mathbb{P}(A_i)\;:\; 0 \leq \textstyle\sum_i a_i \mathbf{1}_{A_i} \leq X,\; n \geq 1 \Big\} \in [0,\infty], where the a_i \geq 0 and A_i \in \mathcal{F}: we approximate X from below by simple functions.

For X of arbitrary sign, X = X^+ - X^- and \mathbb{E}[X] = \mathbb{E}[X^+] - \mathbb{E}[X^-] if both terms are finite (we then say X is integrable, written X \in L^1).

The variance is \mathrm{Var}(X) = \mathbb{E}[(X-\mathbb{E}X)^2].

Theorem 1.2 — Monotone convergence, linearity, monotonicity

  • Monotone convergence (Beppo-Levi): if 0 \leq X_n \uparrow X (increasing, pointwise) then \mathbb{E}[X_n] \uparrow \mathbb{E}[X], even if the limit is +\infty — it is the tool that makes every limit/integral swap legitimate in the nonnegative case;
  • Linearity: if X,Y \in L^1, \mathbb{E}[aX+bY] = a\,\mathbb{E}[X] + b\,\mathbb{E}[Y] — with no independence assumption;
  • Monotonicity and domination: X \leq Y implies \mathbb{E}[X] \leq \mathbb{E}[Y]; if |X| \leq Y with Y \in L^1 then X \in L^1.

Theorem 1.3 — Tonelli and Fubini Let (X_1,\mathcal{F}_1,\mu_1) and (X_2,\mathcal{F}_2,\mu_2) be two \sigma-finite measure spaces, and f : X_1 \times X_2 \to \mathbb{R} measurable.

  • Tonelli (nonnegative functions): if f \geq 0, \int_{X_1 \times X_2} f\,d(\mu_1 \otimes \mu_2) = \int_{X_1}\Big(\int_{X_2} f(x_1,x_2)\,d\mu_2\Big) d\mu_1 = \int_{X_2}\Big(\int_{X_1} f(x_1,x_2)\,d\mu_1\Big) d\mu_2, and the three quantities may equal +\infty;
  • Fubini (integrability): if \iint |f|\,d(\mu_1\otimes\mu_2) < \infty, the three integrals above coincide and are finite.

In probability: for independent X, Y and measurable g \geq 0, \mathbb{E}[g(X,Y)] = \iint g(x,y)\,d\mathbb{P}_X(x)\,d\mathbb{P}_Y(y) — the variables are “decoupled”.

Classic counterexample: f(x,y) = \tfrac{x^2-y^2}{(x^2+y^2)^2} on (0,1]^2: the two iterated integrals equal \pi/4 and -\pi/4 (here \iint |f| = \infty) — the integrability assumption is not decorative.

Proposition 1.4 — Expectation of a mixture (worked example) Let X be drawn from the mixture 0.3\,\mathcal{N}(-1,\,0.5^2) + 0.7\,\mathcal{N}(2,\,1^2). Then \mathbb{E}[X] = 0.3 \times (-1) + 0.7 \times 2 = 1.1 and \mathrm{Var}(X) = \mathbb{E}[\mathrm{Var}(X \mid J)] + \mathrm{Var}(\mathbb{E}[X \mid J]) = \big(0.3 \times 0.25 + 0.7 \times 1\big) + 0.3 \times 0.7 \times 3^2 = 0.775 + 1.89 = 2.665, where J is the component index (the law of total variance is proved in chapter 6).

Gaussian mixtures serve as the running example of the whole module: they are also the target distributions of generative models (see the Machine Learning module, chapter 7, and the Deep Learning module, chapter 9).

Example 1.5 — The Gaussian integral, via Fubini and a change to polar coordinates I^2 = \int_{\mathbb{R}}\int_{\mathbb{R}} e^{-(x^2+y^2)}\,dx\,dy \overset{\text{polar}}{=} \int_0^{2\pi}\!\!\int_0^{+\infty} e^{-r^2}\,r\,dr\,d\theta = 2\pi \times \frac12 = \pi, hence I = \sqrt{\pi} and \int_{\mathbb{R}} e^{-u^2/2}du = \sqrt{2\pi}: the normalization constant of the Gaussian is not magic.

The Jacobian dx\,dy = r\,dr\,d\theta — the factor r that “saves” the integral — is the same one that will appear in the proof of Box-Muller (Prop. 3.4).

Numerical check: \sqrt{2\pi} \approx 2.5066.

What to remember from this chapter The expectation is a Lebesgue integral: to swap it with another integral (expectation, sum, limit), it suffices to have either positivity (Tonelli, Beppo-Levi) or an L^1 domination (Fubini, dominated convergence). All the convergence proofs of the following chapters amount to checking one of these two assumptions.

2. Convergence: LLN, CLT, delta method

A Monte Carlo estimate is an average of random draws; to trust it, one must know in what sense it approaches the true value, and how large its error is for a given number of draws. This chapter defines the modes of convergence, proves the law of large numbers and the central limit theorem, and derives the delta method, which transfers the CLT to smooth functions of an average.

Definition 2.1 — Modes of convergence Let (X_n) be a sequence of r.v. and X a real r.v.

  • In probability: \forall \varepsilon > 0,\; \mathbb{P}(|X_n - X| > \varepsilon) \to 0;
  • Almost surely: \mathbb{P}(\{\omega : X_n(\omega) \to X(\omega)\}) = 1;
  • In L^p: \mathbb{E}|X_n - X|^p \to 0;
  • In distribution: \mathbb{E}[f(X_n)] \to \mathbb{E}[f(X)] for every bounded continuous f — the only mode where X_n and X may live on different spaces.

Classic implications: L^p and a.s. imply in probability; in probability implies in distribution; no other general implication.

(Counterexample: the dyadic “sliding window” X_n = \mathbf{1}_{[j/2^k,\,(j+1)/2^k]} with n = 2^k + j on [0,1] equipped with Lebesgue measure converges in probability to 0 but takes the value 1 infinitely often — no almost-sure convergence.)

Theorem 2.2 — (Weak) law of large numbers (proved) Let X_1, X_2, \dots be i.i.d. and square-integrable, with expectation \mu. Then \bar{X}_n = \frac1n \sum_{i=1}^n X_i \to \mu \quad \text{in probability (and in } L^2).

Proof. Linearity (Thm 1.2): \mathbb{E}[\bar X_n] = \mu.

Independence and Fubini (Thm 1.3): \mathrm{Var}(\bar X_n) = \frac{1}{n^2}\sum_i \mathrm{Var}(X_i) = \frac{\sigma^2}{n}.

Chebyshev (Prop. 0.2): \mathbb{P}(|\bar X_n - \mu| > \varepsilon) \leq \sigma^2/(n\varepsilon^2) \to 0, and \mathbb{E}|\bar X_n - \mu|^2 = \sigma^2/n \to 0.∎

The strong version (almost sure, under the sole assumption \mathbb{E}|X_1| < \infty) requires the Borel-Cantelli lemma and Kolmogorov’s maximal inequality: admitted here, it justifies the frequentist interpretation of probabilities and the convergence of ergodic chains (ch. 7 and 8).

Theorem 2.3 — Central limit theorem (proved via characteristic functions) Let X_1, X_2, \dots be i.i.d., \mathbb{E}X_1 = \mu, 0 < \sigma^2 = \mathrm{Var}(X_1) < \infty. Then

Key result — central limit theorem \frac{\sqrt{n}}{\sigma}\big(\bar X_n - \mu\big) \;\xrightarrow[n \to \infty]{\text{law}}\; \mathcal{N}(0,1).

Proof.

  1. Reduction: assume \mu = 0 (replace X_i by X_i - \mu). Set \varphi(u) = \mathbb{E}[e^{iuX_1}], continuous at 0 with \varphi(0)=1.
  2. Taylor of \varphi: since \mathbb{E}|X_1|^2 < \infty, we may differentiate twice under the expectation (domination): \varphi(u) = 1 - \tfrac{\sigma^2 u^2}{2} + u^2\,\varepsilon(u), \qquad \varepsilon(u) \to 0. Setting \psi = \log \varphi (defined near 0) and using \log(1+z) = z + o(z): \psi(u) = -\frac{\sigma^2 u^2}{2} + u^2\,\tilde\varepsilon(u), \qquad \tilde\varepsilon(u) \to 0.
  3. Product: by independence, the characteristic function of S_n = \sqrt{n}\,\bar X_n/\sigma equals \varphi_n(t) = \varphi(t/(\sigma\sqrt n))^n, hence \log \varphi_n(t) = n\,\psi\Big(\frac{t}{\sigma\sqrt n}\Big) = n\Big(-\frac{t^2}{2n} + \frac{t^2}{n}\tilde\varepsilon\big(t/(\sigma\sqrt n)\big)\Big) \xrightarrow[n\to\infty]{} -\frac{t^2}{2}.
  4. Conclusion: \varphi_n(t) \to e^{-t^2/2}, which is the characteristic function of \mathcal{N}(0,1); Lévy’s continuity theorem (a pointwise limit of characteristic functions continuous at 0 is a characteristic function, and convergence of characteristic functions is equivalent to convergence in distribution — admitted) concludes the proof.∎

Theorem 2.4 — Delta method (proved) If \sqrt{n}(T_n - \theta) \xrightarrow{\text{law}} \mathcal{N}(0,\sigma^2) and g : \mathbb{R} \to \mathbb{R} is \mathcal{C}^1 in a neighborhood of \theta with g'(\theta) \neq 0, then \sqrt{n}\big(g(T_n) - g(\theta)\big) \xrightarrow{\text{law}} \mathcal{N}\big(0,\; \sigma^2\, g'(\theta)^2\big).

Proof. Mean value theorem: on the event |T_n - \theta| \leq \delta (where g is \mathcal{C}^1), g(T_n) - g(\theta) = g'(\xi_n)\,(T_n - \theta) for some \xi_n between \theta and T_n.

Since \sqrt n (T_n - \theta) converges in distribution, it is tight (\mathcal{O}_\mathbb{P}(1)), so T_n - \theta = \mathcal{O}_\mathbb{P}(n^{-1/2}) \to 0 in probability.

The probability of the event |T_n - \theta| > \delta tends to 0, and \xi_n \to \theta in probability, hence g'(\xi_n) \to g'(\theta) in probability by continuity of g'.

Therefore \sqrt n\,(g(T_n) - g(\theta)) = g'(\xi_n)\,\sqrt n (T_n-\theta) outside an event of vanishing probability, and Slutsky’s lemma gives the limit g'(\theta)\,\mathcal{N}(0,\sigma^2) = \mathcal{N}(0, \sigma^2 g'(\theta)^2). ∎

Example 2.5 — Intervals and variance stabilization (numbers)

  • A poll with n = 1000 on a proportion p has standard error \sqrt{p(1-p)/n} \leq \sqrt{1/(4n)} \approx 1.58\,\%: the “margin of error ±3 points” quoted by polling institutes is a 95% interval (CLT + \Phi^{-1}(0.975) = 1.96).
  • For T_n = \bar X_n and g = \log, the limiting variance becomes \sigma^2/\theta^2; in a family where the standard deviation is proportional to the mean (exponential distributions, for instance, where \sigma = \theta), it equals 1 and no longer depends on the parameter — this is the principle of variance-stabilizing transformations, used before the computer age to make variances homoscedastic.
  • For the empirical correlation coefficient r of a Gaussian pair, Fisher’s transformation g(r) = \tfrac12\log\frac{1+r}{1-r} gives a limiting Gaussian distribution with variance 1/(n-3) — a classic example of the delta method in dimension 2 (with the gradient).

3. Simulating: inverse, rejection, Box-Muller

A computer only provides uniform random numbers; every simulation algorithm must turn them into draws from a prescribed distribution. This chapter gives three exact ways of doing so — inverting the distribution function, rejection, and the Box-Muller change of variables — with their proofs and their costs.

Proposition 3.1 — Inverse transform method (proved) Let F be a cumulative distribution function and F^{-1}(u) = \inf\{x : F(x) \geq u\} (generalized inverse). If U \sim \mathcal{U}[0,1], then X = F^{-1}(U) has distribution F.

Proof. F^{-1}(u) \leq x is equivalent to u \leq F(x) (property of the infimum); hence \mathbb{P}(F^{-1}(U) \leq x) = \mathbb{P}(U \leq F(x)) = F(x). ∎

Application: X = -\ln U \sim \mathcal{E}(1) (distribution 1-e^{-x}), and X = \lfloor nU \rfloor + 1 is uniform on \{1,\dots,n\}. Conversely, every algorithm producing “random reals” on a machine truncates a uniform distribution — the only primitive source (together with physical generators) of the whole chapter.

Proposition 3.2 — Rejection method (correction proved) Let f be the target density (with respect to \lambda), and g a proposal density such that f \leq M g with M < \infty.

Algorithm: draw independent X \sim g, U \sim \mathcal{U}[0,1]; accept if U \leq f(X)/(Mg(X)), otherwise start over. Then:

  • the acceptance probability at each trial equals 1/M;
  • the distribution of X conditional on acceptance is exactly f.

Proof. For every Borel set A: \mathbb{P}(X \in A,\ \text{accepted}) = \int_A g(x)\, \frac{f(x)}{Mg(x)}\,dx = \frac{1}{M}\int_A f(x)\,dx = \frac{\pi_f(A)}{M}, where we used the independence of U and X and then Fubini.

Taking A = \mathbb{R}: \mathbb{P}(\text{accepted}) = 1/M. By Bayes’ formula, \mathbb{P}(X \in A \mid \text{accepted}) = \frac{\pi_f(A)/M}{1/M} = \pi_f(A). ∎

The number of trials follows a geometric distribution with parameter 1/M (expectation M): all the art lies in choosing g close to f to minimize M.

Example 3.3 — Simulating \mathcal{N}(0,1) with a Laplace proposal (numbers) Proposal: g(x) = \tfrac12 e^{-|x|}. The ratio \frac{f(x)}{g(x)} = \sqrt{2/\pi}\; e^{-x^2/2 + |x|} is maximal at |x|=1, where -x^2/2+|x| = 1/2.

Hence M = \sqrt{2e/\pi} \approx 1.3155 and the acceptance rate is 1/M = \sqrt{\pi/(2e)} \approx 76\,\%.

On average 1.31 proposals per accepted sample: very efficient, and requiring no knowledge of the normalization constant of f (a truncated distribution, for instance). It is the mechanism behind most generators of “exotic” distributions.

Proposition 3.4 — Box-Muller (proved by change of variables) Let U,V be i.i.d. \mathcal{U}[0,1]. Set R = \sqrt{-2\ln U} and \Theta = 2\pi V.

Then Z_1 = R\cos\Theta and Z_2 = R\sin\Theta are i.i.d. \mathcal{N}(0,1).

Proof. First, \mathbb{P}(R \leq r) = \mathbb{P}(U \geq e^{-r^2/2}) = 1 - e^{-r^2/2}, density f_R(r) = r e^{-r^2/2} (Rayleigh), independent of \Theta (uniform). The pair has density f_{R,\Theta}(r,\theta) = \frac{r}{2\pi} e^{-r^2/2} on (0,\infty) \times (0,2\pi).

Inverse polar change of variables (r,\theta) \mapsto (x,y) = (r\cos\theta, r\sin\theta), with Jacobian \left|\det \frac{\partial(x,y)}{\partial(r,\theta)}\right| = r (direct computation): the density of the pair (Z_1,Z_2) equals f_{Z_1,Z_2}(x,y) = \frac{f_{R,\Theta}(r,\theta)}{r} = \frac{1}{2\pi} e^{-(x^2+y^2)/2}, which is the product of the two densities \varphi(x)\varphi(y): independence and Gaussian marginals.∎

Example 1.5 (the Gaussian integral) provides the constant \frac{1}{2\pi}: the chapters echo one another.

import numpy as np
rng = np.random.default_rng(42)

def box_muller(n):                      # n standard Gaussians (n even)
    u = rng.random(n // 2); v = rng.random(n // 2)
    r = np.sqrt(-2.0 * np.log(u)); t = 2.0 * np.pi * v
    return np.concatenate([r * np.cos(t), r * np.sin(t)])

def gaussian_rejection(n, m=1.3155):    # N(0,1) by rejection with Laplace
    out = []
    while len(out) < n:
        x = rng.laplace(0.0, 1.0)       # density (1/2) exp(-|x|)
        u = rng.random()
        if u < np.exp(-x*x/2.0) / (m * 0.5 * np.exp(-abs(x))):
            out.append(x)
    return np.array(out)

z1, z2 = box_muller(200000), gaussian_rejection(200000)
print(z1.mean(), z1.var())              # ~0.000 , ~1.000
print(z2.mean(), z2.var())              # ~0.001 , ~1.000

def mixture(n):                          # 0.4 N(-2,0.5^2) + 0.6 N(2.5,0.8^2)
    j = rng.random(n) < 0.6
    return np.where(j, 2.5 + 0.8*rng.standard_normal(n),
                       -2.0 + 0.5*rng.standard_normal(n))

Practice In production one uses rng.standard_normal (ziggurat, an optimized rejection variant) — but Box-Muller and rejection remain the pedagogical building blocks and the fallback tools when the target is no longer standard: truncated distributions, distributions with an unknown normalization constant (typical in the Bayesian setting, ch. 8). All the methods in the rest of the module are generalizations of this program: target known up to a constant → i.i.d. samples (rejection, IS) or correlated ones (MCMC).

4. Monte Carlo and variance reduction

Many quantities of interest are expectations that cannot be computed in closed form: an integral in high dimension, a probability of failure, the mean of a posterior distribution. Monte Carlo replaces the expectation by an average of simulated draws.

This chapter computes its error, explains why that error does not depend directly on the dimension, and presents two ways of reducing it at almost no cost: antithetic variables and control variates.

Definition 4.1 — Monte Carlo estimator To estimate \theta = \mathbb{E}[h(X)], X \sim \pi, draw X_1, \dots, X_n i.i.d. from \pi and set \hat\theta_n = \frac1n \sum_{i=1}^n h(X_i).

Then \mathbb{E}[\hat\theta_n] = \theta (unbiased, LLN); \mathrm{Var}(\hat\theta_n) = \sigma_h^2/n where \sigma_h^2 = \mathrm{Var}(h(X_1)); and by the CLT (Thm 2.3),

Key result — Monte Carlo error bar \frac{\sqrt n}{\sigma_h}\big(\hat\theta_n - \theta\big) \approx \mathcal{N}(0,1), \qquad \theta \in \left[\hat\theta_n \pm 1.96\,\frac{\hat\sigma_h}{\sqrt n}\right] \ \text{at 95\%},

with \hat\sigma_h^2 = \frac1{n-1}\sum_i (h(X_i) - \hat\theta_n)^2 .

The (RMSE) error decreases like \sigma_h/\sqrt n, that is like 1/\sqrt n independently of the dimension of the space of X: this is the strength of Monte Carlo over quadrature, whose cost grows exponentially with dimension.

Example 4.2 — Estimating \pi, with error bars (numbers) X,Y i.i.d. \mathcal{U}[-1,1], h = \mathbf{1}_{X^2+Y^2 \leq 1}, \theta = \pi/4. Here \sigma_h^2 = \theta(1-\theta) \approx 0.1685, \sigma_h \approx 0.4105.

For n = 10^4: standard error \approx 0.0041, interval \pm 0.0081 at 95%.

For three exact digits after the decimal point (\pm 5\times10^{-4} on \pi, i.e. 1.25\times10^{-4} on \theta = \pi/4) one needs n \approx (1.96 \times 0.4105 / 1.25\times 10^{-4})^2 \approx 4.1 \times 10^7 .

The price of one additional decimal digit is \times 100 samples: the only way out is to reduce \sigma_h.

Worked example — where the dimension hides To integrate a smooth function over [0,1]^d with a grid of 10 points per axis, a quadrature rule needs 10^d evaluations — 10^{10} in dimension 10.

A rule of order k has an error of order N^{-k/d} for N evaluations, which degrades as d grows.

Monte Carlo with N = 10^6 draws has a standard error \sigma_h/1000 in every dimension: what can grow with d is not the rate but the constant \sigma_h.

Example: estimate the volume V_d of the unit ball by the fraction of uniform points of [-1,1]^d that fall inside it. The indicator has mean p = V_d/2^d and relative standard error \sqrt{(1-p)/(Np)}.

For d = 2, p = \pi/4 \approx 0.785; for d = 10, V_{10} = \pi^5/120 \approx 2.55 and p \approx 0.0025: with the same N, the relative error is about 38 times larger.

Importance sampling (ch. 5) and MCMC (ch. 8) are the answers to this hidden dependence.

Common mistakes (i) Reporting a Monte Carlo estimate without its error bar: the interval of Definition 4.1 costs one line of code.

(ii) Forgetting that the CLT needs a finite variance. With h(u) = u^{-1/2} and U uniform on [0,1], \mathbb{E}[h(U)] = \int_0^1 u^{-1/2}\,du = 2 is finite, so the law of large numbers applies, but \mathbb{E}[h(U)^2] = \int_0^1 u^{-1}\,du = \infty . The estimator converges, slowly and erratically, and the interval \pm 1.96\,\hat\sigma_h/\sqrt n is meaningless because \hat\sigma_h itself does not converge.

(iii) Comparing two methods on a single run each: compare their variances, estimated over repeated runs, not two individual estimates.

Proposition 4.3 — Antithetic variables (example computed exactly) For monotone f, f(U) and f(1-U) are negatively correlated: \mathrm{Var}\Big(\frac{f(U)+f(1-U)}{2}\Big) = \frac{\mathrm{Var}(f(U)) + \mathrm{Cov}(f(U),f(1-U))}{2} \leq \frac{\mathrm{Var}(f(U))}{2}.

Application to I = \int_0^1 \frac{dx}{1+x} = \ln 2 with f(u) = \frac1{1+u}: exact computations give \mathrm{Var}(f(U)) = \tfrac12 - (\ln 2)^2 \approx 0.0195, \qquad \mathbb{E}[f(U)f(1-U)] = \tfrac23 \ln 2 \approx 0.4621, hence \mathrm{Cov} \approx -0.0184 and a per-pair variance \approx 5.5\times10^{-4} versus 9.75\times 10^{-3} for two independent draws: a gain of a factor ~18, for free.

In practice: uniforms (u, 1-u), Gaussians (z, -z), and more generally any measurable transformation with negative covariance.

Proposition 4.4 — Control variates (proved, worked example) Let C be an r.v. with known expectation \mu_C, correlated with h(X). Estimator \hat\theta_\beta = \hat\theta_n - \beta(\bar C_n - \mu_C), unbiased for every \beta. The variance \mathrm{Var}(\hat\theta_\beta) = \frac{1}{n}\big(\sigma_h^2 - 2\beta\,\mathrm{Cov}(h,C) + \beta^2 \sigma_C^2\big) is minimal at \beta^* = \mathrm{Cov}(h,C)/\sigma_C^2, where it equals \frac{\sigma_h^2(1-\rho^2)}{n}, with \rho the correlation: any nonzero correlation improves the estimator.

Proof. Quadratic polynomial in \beta, minimum at \beta^*; the minimal value rewrites as \sigma_h^2(1 - \rho^2) by definition of \rho. The unknown \beta^* is estimated from the sample (small cost, negligible \mathcal{O}(1/n) bias).∎

Example: estimate \mathbb{E}[e^U] = e - 1 \approx 1.7183 with the control C = U (\mathbb{E}C = 1/2):

  • \mathrm{Cov}(e^U, U) = 1 - (e-1)/2 \approx 0.1409, \mathrm{Var}(U) = 1/12, \beta^* \approx 1.6903;
  • \rho^2 \approx 0.984, since \mathrm{Var}(e^U) = \frac{e^2-1}{2} - (e-1)^2 \approx 0.2420 ;
  • hence \mathrm{Var}(e^U)\,(1-\rho^2) \approx 0.0039.

The variance is divided by about 60, because e^u is almost linear on [0,1].

Conditioning (Example 6.5) is a special case where the control is \mathbb{E}[h(X)\mid\mathcal{G}] itself.

import numpy as np
rng = np.random.default_rng(7)

n = 500_000
x, y = rng.uniform(-1, 1, (2, n))
pi_hat = 4.0 * np.mean(x*x + y*y <= 1.0)
se = 4.0 * np.std(x*x + y*y <= 1.0, ddof=1) / np.sqrt(n)
print(f"pi = {pi_hat:.5f} +/- {1.96*se:.5f}")

# antithetic for ln 2
u = rng.random(n // 2)
est = 0.5 * ((1/(1+u)) + (1/(2-u)))
print(f"ln2 = {est.mean():.6f} (variance per draw {est.var(ddof=1):.2e})")

# control variate for E[e^U]
u = rng.random(n)
e = np.exp(u); beta = np.cov(e, u, ddof=1)[0, 1] / u.var(ddof=1)
mc = e - beta * (u - 0.5)
print(f"E[e^U] = {mc.mean():.6f}, e-1 = {np.e-1:.6f}")

Overview of methods Three families to reduce \sigma_h or reach inaccessible distributions: antithetic/control (this chapter); importance sampling (ch. 5); conditioning (ch. 6). And when sampling X \sim \pi directly is impossible (unknown normalization constant): MCMC (ch. 8).

5. Importance sampling

When the event of interest is rare, or when one can only sample from a distribution other than the target, plain Monte Carlo wastes almost all its draws. Importance sampling draws from a better-chosen distribution and corrects with weights.

This chapter computes its variance and its optimal proposal, and quantifies the weight degeneracy that limits it in high dimension.

Definition 5.1 — Importance sampling estimator To estimate \theta = \int h(x) f(x)\,dx = \mathbb{E}_f[h(X)], draw Y_1,\dots,Y_n i.i.d. from a density g (the proposal) with g > 0 everywhere hf \neq 0, and weight by w(y) = f(y)/g(y):

Key result — importance sampling \hat\theta_{\mathrm{IS}} = \frac1n \sum_{i=1}^n w(Y_i)\, h(Y_i), \qquad \mathbb{E}_g[\hat\theta_{\mathrm{IS}}] = \theta \ \text{(unbiased)}.

Exact variance: \mathrm{Var}_g(\hat\theta_{\mathrm{IS}}) = \frac1n\big(\mathbb{E}_g[w^2h^2] - \theta^2\big) = \frac1n\big(\int \tfrac{h^2 f^2}{g} - \theta^2\big), minimal (zero variance) for g^\star \propto |h| f — the optimal proposal concentrates the draws where the target and the function of interest meet.

An indispensable variant: the self-normalized estimator \hat\theta_{\mathrm{SNIS}} = \frac{\sum_i w_i h(Y_i)}{\sum_i w_i}, usable when f is known only up to a constant (the Bayesian case), with bias of order \mathcal{O}(1/n).

Proposition 5.2 — Weight degeneracy and effective sample size (proved) Set \mathrm{cv}^2 = \mathrm{Var}_g(w)/(\mathbb{E}_g[w])^2 (squared coefficient of variation of the weights; here \mathbb{E}_g[w] = 1). The effective sample size is \mathrm{ESS} = \frac{n}{1 + \mathrm{cv}^2}, \qquad \mathrm{cv}^2 = \chi^2(f \,\|\, g) = \int \frac{(f-g)^2}{g}, where \chi^2(f\|g) is the chi-squared divergence.

In particular \mathrm{ESS} \leq n, with equality if and only if f = g, and \mathrm{ESS}/n \to 0 as soon as f and g differ substantially.

Proof. \mathrm{Var}(\bar w) = \mathrm{cv}^2/n where \bar w is the empirical mean of the weights.

For the \chi^2 form: \mathbb{E}_g[w^2] = \int f^2/g and (\mathbb{E}_g w)^2 = 1, hence \mathrm{cv}^2 = \int \frac{f^2}{g} - 1 = \int \frac{(f-g)^2}{g} (expand the square and use \int f = \int g = 1).∎

Gaussian case (exact computation): f = \mathcal{N}(0,1), g = \mathcal{N}(\mu,1) gives w(y) = e^{-\mu y + \mu^2/2} then \mathbb{E}_g[w^2] = e^{\mu^2}, hence \mathrm{ESS}/n = e^{-\mu^2} \qquad (\mu = 2:\ 1.8\%\ ;\ \mu = 3:\ 0.012\%\ ;\ \mu = 4:\ 1.1\times10^{-7}).

In dimension d with a per-coordinate mismatch \mu, the effect multiplies: \mathrm{ESS}/n = e^{-d\mu^2} — the degeneracy of importance sampling is exponential in dimension, where only an adapted proposal (sequential adaptation, particle methods — SMC) survives.

Example 5.3 — Tail probability p = \mathbb{P}(Z > 4) = 3.17\times10^{-5} (numbers)

  • Crude MC: expected number of “hits” np; for a 10% relative error one needs n \approx \frac{1-p}{p \times 0.01} \approx 3.2\times10^6 \text{ draws};
  • IS, exponential tilt g = \mathcal{N}(4,1): exact computation \mathbb{E}_g[w^2 \mathbf{1}_{Z>4}] = e^{16}\,\Phi(-8) \approx 5.5\times10^{-9}, i.e. a per-draw standard deviation \approx 7\times10^{-5} versus p \approx 3.2 \times 10^{-5} for the estimator: relative error ~2.2/\sqrt n — 500 draws suffice where three million were needed;
  • Optimal IS: sample directly in the tail (g = f conditioned on Z>4, by rejection): constant weight w = 1/p, zero variance — a literal illustration of g^\star \propto |h| f.

Moral: IS turns a rare-event problem into the sampling of typical events — a central technique in reliability, finance (VaR), and Bayesian inference (sequential methods).

import numpy as np
from scipy import stats
rng = np.random.default_rng(2024)

n = 200_000
p_exact = 1 - stats.norm.cdf(4.0)               # 3.167e-5

mc = rng.standard_normal(n) > 4.0               # crude Monte Carlo
g = rng.normal(4.0, 1.0, n)                     # exponential tilt
w = np.exp(-4.0*g + 8.0)                        # f/g, N(0,1)/N(4,1)
isw = w * (g > 4.0)

for name, est in [("crude", mc.mean()), ("IS", isw.mean())]:
    print(f"{name:5s} {est:.3e}  (exact {p_exact:.3e})")

ess = n / (1.0 + w.var(ddof=1))                 # ESS on the overall weights
print(f"ESS = {ess:.1f} / {n}")                 # weights highly degenerate outside the tail

Usage diagnostics Always report \mathrm{ESS} and the histogram of the weights: a few overwhelming weights mean the estimator “rests” on a handful of draws (unstable variance). Remedies: weight truncation, self-normalization, or moving to an adaptive method (SMC); in high dimension, prefer MCMC (ch. 8) or Langevin (ch. 9). ESS will reappear as a central diagnostic of MCMC chains in chapter 8.

6. Conditional expectation

A prediction can only use the information available, and an estimator can often be improved by averaging out what is irrelevant to it. Conditional expectation formalizes both ideas: it is the best prediction of a variable given some information.

This chapter defines it in full generality and proves the tower property and the law of total variance, the two rules used by variance reduction and by Markov chains.

Definition 6.1 — General conditional expectation Let X \in L^1 and \mathcal{G} \subseteq \mathcal{F} be a sub-sigma-algebra. The conditional expectation \mathbb{E}[X \mid \mathcal{G}] is the unique (up to a null set) r.v. Y such that:

(i) Y is \mathcal{G}-measurable;

(ii) for every A \in \mathcal{G}, \int_A Y\,d\mathbb{P} = \int_A X\,d\mathbb{P}.

If \mathcal{G} = \sigma(Z), we write \mathbb{E}[X \mid Z].

Hilbertian interpretation (for X \in L^2): it is the orthogonal projection of X onto the closed subspace of square-integrable \mathcal{G}-measurable r.v. — the best least-squares approximation of X by a function of the available information \mathcal{G}.

All of regression is right there (see the Refresher Statistics module, chapter 7, and the Machine Learning module, chapter 2).

Proposition 6.2 — Tower property (proved) For every sub-sigma-algebra \mathcal{H} \subseteq \mathcal{G} and X \in L^1: \mathbb{E}\big[\,\mathbb{E}[X \mid \mathcal{G}] \,\big|\, \mathcal{H}\,\big] = \mathbb{E}[X \mid \mathcal{H}] \quad \text{a.s.}

Proof. Set Y = \mathbb{E}[X \mid \mathcal{H}]. Candidate for the identity: Y itself.

  1. Y is \mathcal{H}-measurable, hence a fortiori a candidate for the conditional expectation of \mathbb{E}[X \mid \mathcal{G}] given \mathcal{H} (the outer operator conditions on \mathcal{H}, the smaller one).
  2. For every A \in \mathcal{H}: since A \in \mathcal{H} \subseteq \mathcal{G}, the definition of \mathbb{E}[X \mid \mathcal{G}] (applied to A) gives \int_A \mathbb{E}[X \mid \mathcal{G}]\,d\mathbb{P} = \int_A X\,d\mathbb{P}, and the definition of Y gives \int_A Y\,d\mathbb{P} = \int_A X\,d\mathbb{P}.
  3. Hence, for every A \in \mathcal{H}, \int_A \mathbb{E}[\mathbb{E}[X \mid \mathcal{G}] \mid \mathcal{H}]\,d\mathbb{P} = \int_A \mathbb{E}[X\mid\mathcal{G}]\,d\mathbb{P} = \int_A Y\,d\mathbb{P}; by uniqueness in Definition 6.1, the identity is proved.∎

Geometrically: projecting onto L^2(\mathcal{G}) and then onto L^2(\mathcal{H}) is the same as projecting directly onto L^2(\mathcal{H}).

Proposition 6.3 — Formula sheet (some points admitted)

  • Linearity, monotonicity, convexity (Jensen): for convex \varphi (proof by convex duality, admitted), \varphi(\mathbb{E}[X \mid \mathcal{G}]) \leq \mathbb{E}[\varphi(X) \mid \mathcal{G}];
  • Taking out of the sigma-algebra: if Z is \mathcal{G}-measurable and bounded, \mathbb{E}[ZX \mid \mathcal{G}] = Z\,\mathbb{E}[X \mid \mathcal{G}]; independence: if X is independent of \mathcal{G}, \mathbb{E}[X \mid \mathcal{G}] = \mathbb{E}[X];
  • Gaussian case: if (X,Y) is Gaussian, \mathbb{E}[X \mid Y] = \mathbb{E}X + \mathrm{Cov}(X,Y)\,\mathrm{Var}(Y)^{-1} (Y - \mathbb{E}Y): the projection is affine — this is exactly the update step of the Kalman filter and the formula of kriging (Gaussian-process regression).

Proposition 6.4 — Total variance (proved) For X \in L^2 and any sub-sigma-algebra \mathcal{G}:

Key result — law of total variance \mathrm{Var}(X) = \mathbb{E}\big[\mathrm{Var}(X \mid \mathcal{G})\big] + \mathrm{Var}\big(\mathbb{E}[X \mid \mathcal{G}]\big).

Proof. By the tower property with \mathcal{H} = \{\emptyset, \Omega\}, \mathbb{E}[X^2] = \mathbb{E}[\mathbb{E}[X^2 \mid \mathcal{G}]] = \mathbb{E}[\mathrm{Var}(X \mid \mathcal{G}) + \mathbb{E}[X \mid \mathcal{G}]^2].

On the other hand \mathrm{Var}(\mathbb{E}[X \mid \mathcal{G}]) = \mathbb{E}[\mathbb{E}[X \mid \mathcal{G}]^2] - \mathbb{E}[X]^2 \quad \text{and} \quad \mathbb{E}[X] = \mathbb{E}[\mathbb{E}[X \mid \mathcal{G}]].

Combining: \mathrm{Var}(X) = \mathbb{E}[X^2] - \mathbb{E}[X]^2 = \mathbb{E}[\mathrm{Var}(X\mid\mathcal{G})] + \mathbb{E}[\mathbb{E}[X \mid \mathcal{G}]^2] - \mathbb{E}[X]^2, which is the announced sum.∎

Example 6.5 — Conditioning reduces variance (full computation) Let U, V be i.i.d. \mathcal{U}[0,1] and X = U + V. Then \mathbb{E}[X \mid U] = U + \tfrac12, \mathrm{Var}(X \mid U) = \mathrm{Var}(V) = \tfrac{1}{12}, and Prop. 6.4 recovers \mathrm{Var}(X) = \tfrac{1}{12} + \mathrm{Var}(U + \tfrac12) = \tfrac{1}{12} + \tfrac{1}{12} = \tfrac16 .

Monte Carlo application (ch. 4): the conditioned estimator U + \tfrac12 has variance 1/12 < 1/6, the same expectation, and less randomness — this is the principle of conditioning-based control variates.

Likewise for estimating \theta = \mathbb{P}(X \in A): \mathbb{E}[\mathbb{P}(X \in A \mid \mathcal{G})] = \theta with a systematically smaller variance (the total variance decomposes into “noise eliminated by conditioning” plus a remainder).

Worked example — two dice Let D_1, D_2 be two fair dice and S = D_1 + D_2. By symmetry \mathbb{E}[D_1 \mid S] = \mathbb{E}[D_2 \mid S], and the two add up to \mathbb{E}[S \mid S] = S, so \mathbb{E}[D_1 \mid S] = S/2 .

Check on one value: given S = 10, the pairs (4,6), (5,5), (6,4) are equally likely and the mean of the first die is 5 = 10/2.

The conditional expectation is a random variable, a function of S: its mean is \mathbb{E}[S]/2 = 3.5 = \mathbb{E}[D_1] (tower property with the trivial sigma-algebra).

Its variance is \mathrm{Var}(S)/4 = (35/6)/4 = 35/24 \approx 1.46, half of \mathrm{Var}(D_1) = 35/12 \approx 2.92. Prop. 6.4 accounts for the other half: \mathbb{E}[\mathrm{Var}(D_1 \mid S)] = 35/24 as well.

7. Markov chains: stationarity, reversibility, ergodicity

When independent draws from a distribution are out of reach, one can still build a random sequence whose distribution converges to it: a Markov chain. This chapter sets up Markov kernels and invariant and reversible distributions, and states the ergodic theorem, which turns averages along a single trajectory into estimates of expectations.

Definition 7.1 — Markov kernel, Markov chain A Markov kernel on a measurable space (E,\mathcal{E}) is a map P : E \times \mathcal{E} \to [0,1] such that P(x,\cdot) is a probability for every x and P(\cdot,A) is measurable for every A.

A sequence (X_k)_{k \geq 0} of r.v. is a Markov chain with kernel P if \mathbb{P}(X_{k+1} \in A \mid X_0, \dots, X_k) = P(X_k, A) (memory reduces to the present).

The n-step distribution is P^n(x,A) (composition of kernels, Fubini for kernels — the analogue of matrix multiplication in finite dimension).

Definition 7.2 — Invariance, reversibility, irreducibility, periodicity

  • \pi is invariant if \pi P = \pi, i.e. \int \pi(dx) P(x,A) = \pi(A) for every A;
  • P is \pi-reversible if \pi(dx)P(x,dy) = \pi(dy)P(y,dx) (detailed balance); reversibility implies invariance (symmetry of the flow), the converse is false;
  • P is \pi-irreducible if for every pair (x, A) with \pi(A) > 0, there exists n (depending on (x,A)) such that P^n(x,A) > 0: everything can be reached;
  • the period of x is the gcd of the n such that P^n(x,\{x\}) > 0 (in a countable space); P is aperiodic if all periods equal 1.

Theorem 7.3 — Convergence and ergodicity (statement) Let P have an invariant probability \pi, and be \pi-irreducible and aperiodic. Then:

  • \pi is the unique invariant distribution;
  • convergence to equilibrium: for \pi-almost every starting point x, \|P^n(x,\cdot) - \pi\|_{\mathrm{TV}} \to 0, where \|\mu - \nu\|_{\mathrm{TV}} = \sup_A |\mu(A) - \nu(A)|;
  • ergodic strong law: for f with \pi(|f|) < \infty and \pi-almost every X_0 = x, almost surely \frac1n \sum_{k=1}^{n} f(X_k) \to \pi(f) = \int f\,d\pi .

If moreover P is Harris recurrent (from every starting point, each set A with \pi(A) > 0 is visited infinitely often, almost surely), both limits hold for every initial distribution \lambda.

This is the case of an irreducible chain on a finite or countable space, and of every \pi-irreducible Metropolis-Hastings chain (Tierney, 1994).

Reversibility is not needed: it is only the easiest way to check that \pi is invariant (Def. 7.2).

It is this theorem that turns a dependent trajectory into a “usable average sample” — the engine of all the MCMC methods of chapter 8.

Proofs: Levin, Peres and Wilmer (finite chains) and Norris (countable chains); general spaces in Roberts and Rosenthal (2004) and Tierney (1994) — see the References.

Example 7.4 — Two states, explicit computations On E = \{1,2\}, P = \begin{pmatrix} 0.7 & 0.3 \\ 0.2 & 0.8 \end{pmatrix}.

  1. Invariance: \pi = \pi P gives 0.3\pi_1 = 0.2\pi_2, i.e. \pi = (0.4\,;\,0.6).
  2. Spectrum: 1 and 0.5, hence P^n = \Pi + 0.5^n\,R (spectral decomposition): the distance to equilibrium decreases exactly like 0.5^n. The mixing time is the first time at which the worst starting point is \varepsilon-close to equilibrium, t_{\mathrm{mix}}(\varepsilon) = \min\big\{n \geq 0 : \max_x \|P^n(x,\cdot) - \pi\|_{\mathrm{TV}} \leq \varepsilon\big\}; here the worst start is state 1 (point 4), so t_{\mathrm{mix}}(\varepsilon) = \lceil \log_2(0.6/\varepsilon)\rceil, \qquad t_{\mathrm{mix}}(0.01) = 6 .
  3. Check of reversibility: \pi_1 P_{12} = 0.4 \times 0.3 = 0.12 = 0.6 \times 0.2 = \pi_2 P_{21} \ ✓
  4. Explicitly, starting from state 1, \mathbb{P}(X_n = 1) = 0.4 + 0.6 \times 0.5^n: 0.7 after one step, 0.475 after three, about 0.419 after five.

From state 1 the total-variation distance to \pi is 0.6 \times 0.5^n (from state 2, 0.4 \times 0.5^n), below 0.01 as soon as n \geq 6 — whatever the starting state, the chain has forgotten it after a handful of steps.

Example 7.5 — Gaussian AR(1) (general space) X_{k+1} = a X_k + \varepsilon_k, |a| < 1, \varepsilon_k i.i.d. \mathcal{N}(0,\tau^2).

If X_0 \sim \mathcal{N}(0, \tau^2/(1-a^2)) then all the X_k follow this distribution (stability under Gaussian convolution): it is a Markov chain on \mathbb{R} with an explicit invariant distribution.

It is reversible, although the kernel \mathcal{N}(ax, \tau^2) is not symmetric in the gap y - x: at stationarity the pair (X_k, X_{k+1}) has density \pi(x)\,p(x,y) \propto \exp\Big(-\frac{x^2 - 2a\,xy + y^2}{2\tau^2}\Big), symmetric in (x, y) — a centred Gaussian pair with equal variances, hence exchangeable.

It is the exact prototype of a well-tuned random walk Metropolis (ch. 8) and of the Gaussian ULA (ch. 9).

Connection with ML Markov chains appear everywhere: Gibbs samplers for Bayesian inference (see the Refresher Statistics module, section 2.7); latent Markov chains of state-space models; stochastic optimization trajectories; and the diffusion processes of generative models (ch. 9, see the Multimodal GenAI module, chapter 3). The irreducibility/aperiodicity pair respectively guarantees accessibility of the whole space and the absence of locked oscillations.

8. MCMC: Metropolis-Hastings, Gibbs, diagnostics, annealing

This chapter puts the two previous ideas together: a Markov chain (ch. 7) built so that its invariant distribution is a prescribed target known only up to a constant, whose trajectory averages replace the independent averages of Monte Carlo (ch. 4).

It presents the Metropolis-Hastings and Gibbs algorithms, proves that they leave the target invariant, and explains how to diagnose their convergence.

Definition 8.1 — Metropolis-Hastings kernel Let \pi be a target density on E (known up to a constant: only \pi(x) is involved, never its total mass) and q(x,dy) a proposal kernel.

The Metropolis-Hastings algorithm builds a Markov chain (X_k): from X_k = x, draw Y \sim q(x,\cdot) and U \sim \mathcal{U}[0,1]; set

Key result — Metropolis-Hastings step X_{k+1} = \begin{cases} Y & \text{if } U \leq \alpha(x,Y),\\ x & \text{otherwise (rejection: the chain stays put),}\end{cases} \qquad \alpha(x,y) = \min\Big(1,\ \frac{\pi(y)\, q(y,x)}{\pi(x)\, q(x,y)}\Big),

where q(x,y) denotes the density of q(x,\cdot) at the point y (with respect to some fixed reference measure).

Special cases:

  • random walk MH (q(x,\cdot) = \mathcal{N}(x, s^2 I), q(y,x)=q(x,y) so \alpha = \min(1,\pi(y)/\pi(x)));
  • independence sampler (q(x,\cdot) = g fixed);
  • MALA (proposal derived from Langevin dynamics, ch. 9).

Theorem 8.2 — Detailed balance of the MH kernel (proved) The Metropolis-Hastings transition kernel, P(x,dy) = q(x,dy)\,\alpha(x,y) + \Big(1 - \int \alpha(x,z)\,q(x,dz)\Big)\,\delta_x(dy), is \pi-reversible: \pi(dx)\,P(x,dy) = \pi(dy)\,P(y,dx). In particular \pi is invariant.

Proof. The rejection term charges only the diagonal \{x = y\}, where the equality to be proved is trivial.

For the acceptance term, set \rho(x,y) = \pi(x)\,q(x,y) (densities with respect to a common dominating measure, e.g. Lebesgue; the case of general kernels is written with the measures \pi(dx)q(x,dy) and treated identically). Let us verify that \rho(x,y)\,\alpha(x,y) is symmetric in (x,y), by case analysis:

  • if \rho(y,x) \leq \rho(x,y): \alpha(x,y) = \rho(y,x)/\rho(x,y) and \alpha(y,x) = 1, hence \rho(x,y)\alpha(x,y) = \rho(y,x) = \rho(y,x)\alpha(y,x);
  • if \rho(y,x) > \rho(x,y): symmetrically \alpha(x,y) = 1 and \alpha(y,x) = \rho(x,y)/\rho(y,x), same conclusion.

In both cases \rho(x,y)\alpha(x,y) = \min(\rho(x,y), \rho(y,x)), an expression symmetric in (x,y): the detailed balance \pi(dx)P(x,dy) = \pi(dy)P(y,dx) is proved.

Invariance: write \mu(dx,dy) = \pi(dx)\,q(x,dy)\,\alpha(x,y) (symmetric) and r(x) = \int q(x,dz)\alpha(x,z). For every Borel set A, (\pi P)(A) = \mu(E \times A) + \int_A \big(1 - r(x)\big)\,\pi(dx). By symmetry of \mu, its marginal in the second variable equals \mu(E,dy) = \int \mu(dx,dy) = \int \mu(dy,dx) = \pi(dy)\,r(y), hence \mu(E\times A) = \int_A r\,d\pi and (\pi P)(A) = \int_A r\,d\pi + \int_A (1-r)\,d\pi = \pi(A). ∎

Only \pi being known up to a constant is required: if \pi = \tilde\pi/Z, Z cancels in \alpha — hence the success of MH in Bayesian inference (see the Refresher Statistics module, chapter 8).

Worked example — a Metropolis-Hastings kernel by hand Target \pi = (0.2, 0.3, 0.5) on \{1, 2, 3\} (only the ratios matter, so the unnormalized weights (2, 3, 5) would do as well); proposal: one of the two other states, uniformly, so q is symmetric and \alpha(x,y) = \min(1, \pi(y)/\pi(x)).

  • From state 1, both moves are accepted: P(1,\cdot) = (0, \tfrac12, \tfrac12).
  • From state 2, the move to 1 is accepted with probability 0.2/0.3 = 2/3 and the move to 3 always: P(2,\cdot) = (\tfrac13, \tfrac16, \tfrac12), the \tfrac16 being the rejected proposals.
  • From state 3: P(3,\cdot) = (0.2, 0.3, 0.5).

Detailed balance holds pair by pair: \pi_1 P_{12} = 0.1 = \pi_2 P_{21}, \qquad \pi_1 P_{13} = 0.1 = \pi_3 P_{31}, \qquad \pi_2 P_{23} = 0.15 = \pi_3 P_{32}.

The chain stays put more often where \pi is large relative to its neighbours, which is exactly how it spends the right fraction of time in each state.

Proposition 8.3 — Gibbs = block-wise Metropolis-Hastings (proved) Let \pi be a density on \mathbb{R}^d and, for i \in \{1,\dots,d\}, the full conditional distribution \pi(x_i \mid x_{-i}).

The Gibbs kernel for “coordinate i”: x \to y = (x_{-i}, y_i) with y_i \sim \pi(\cdot \mid x_{-i}), is an MH kernel with acceptance probability 1.

Proof. This is MH with the degenerate proposal q_i(x,dy) = \pi(y_i \mid x_{-i})\, \delta_{x_{-i}}(dy_{-i}).

The acceptance ratio between x and y (which differ only in coordinate i) equals \frac{\pi(y)\,\pi(x_i \mid y_{-i})}{\pi(x)\,\pi(y_i \mid x_{-i})} = \frac{\pi(y_{-i})\,\pi(y_i \mid y_{-i})\,\pi(x_i \mid y_{-i})} {\pi(x_{-i})\,\pi(x_i \mid x_{-i})\,\pi(y_i \mid x_{-i})} = 1, since y_{-i} = x_{-i} (decomposition \pi(x) = \pi(x_{-i})\pi(x_i\mid x_{-i})).

Hence \alpha \equiv 1: we always accept, and detailed balance (Thm 8.2) guarantees the invariance of \pi for each sweep.∎

The systematic scan (coordinates 1 to d) or random scan (uniform coordinate) composes these kernels: a composition of \pi-invariant kernels is a \pi-invariant kernel. Gibbs is the building block of conditional Bayesian sampling (graphical models, mixture models — see the Machine Learning module, chapter 7, for the EM side).

Proposition 8.4 — Applied ergodic theorem and chain CLT (statements) If the MH kernel is \pi-irreducible and aperiodic (checked as soon as q charges a neighborhood of 0 or the rejection probability is nonzero):

  • ergodicity (Thm 7.3): \frac1n\sum_{k=1}^n h(X_k) \to \pi(h) a.s. for h \in L^1(\pi);
  • Markov chain CLT (for instance for a reversible, geometrically ergodic chain): \sqrt n\,(\hat\mu_{\mathrm{MH}} - \pi(h)) \to \mathcal{N}(0, \sigma_{\mathrm{MH}}^2), \qquad \sigma_{\mathrm{MH}}^2 = \mathrm{Var}_\pi(h(X_0)) + 2\sum_{k\geq1} \mathrm{Cov}_\pi(h(X_0), h(X_k)): positive autocorrelation inflates the effective variance — hence the correction factor \tau = 1 + 2\sum_k \rho_k (“integrated autocorrelation time”).

Definition 8.5 — Convergence diagnostics and chain ESS

  • Trace (trajectory of (X_k) per coordinate): visible mixing, mode trapping (the chain stays stuck in one mode of a multimodal target);
  • Autocorrelogram: \rho_k as a function of the lag k; slow decay = slow exploration;
  • Chain ESS: \mathrm{ESS} = n/\tau with \tau = 1 + 2\sum_{k=1}^{K}\rho_k (truncation by Geyer’s heuristic); MCMC error bar \approx \hat\sigma_h \sqrt{\tau/n};
  • Gelman-Rubin \hat R: several chains started from overdispersed initializations; convergence when the between-chain and within-chain variances balance (\hat R \to 1, usual threshold 1.01-1.1);
  • acceptance rate: for random walk MH, the theoretically optimal scale gives an acceptance rate of ~0.234 on product targets in high dimension, and ~0.44 for a one-dimensional Gaussian target; a step that is too small explores slowly, too large rejects everything.

Proposition 8.6 — Simulated annealing (statement) To minimize a potential U, one samples \pi_T(x) \propto e^{-U(x)/T}, the Gibbs distribution of ch. 9 at temperature T (T = 1 gives e^{-U}), with T decreasing like T_k = c/\log(k+1).

Under this schedule, with c at least the depth of the deepest local minimum that is not global (Hajek’s theorem, stated, on a finite space), the probability that the chain sits in the set of global minima tends to 1. In practice T_k = T_0 \times 0.95^k (geometric, no guarantee).

Annealing is the interface between sampling and optimization: high temperatures to explore, low ones to exploit — the same trade-off as the noise schedules of diffusion models (ch. 9).

import numpy as np
rng = np.random.default_rng(0)

# target: bimodal mixture 0.5 N(-2.5, 0.7^2) + 0.5 N(2.5, 0.7^2)
logpi = lambda x: np.logaddexp(-((x+2.5)**2)/(2*0.49),
                               -((x-2.5)**2)/(2*0.49))

def rw_mh(x0, n, s):
    x = np.empty(n); x[0] = x0; acc = 0
    for k in range(n-1):
        y = x[k] + s * rng.standard_normal()
        if np.log(rng.random()) < logpi(y) - logpi(x[k]):
            x[k+1] = y; acc += 1
        else:
            x[k+1] = x[k]
    return x, acc/n

x, rate = rw_mh(0.0, 200_000, 4.0)     # large step to jump between modes
print(f"acceptance {rate:.3f}, mean {x[1000:].mean():+.3f} (exact 0)")

def ess(z):                            # truncated positive autocorrelations
    z = z - z.mean(); n = len(z)
    acf = [1.0] + [np.corrcoef(z[:-k], z[k:])[0,1] for k in range(1, 200)]
    tau, s = 1.0, 0.0
    for k in range(1, len(acf), 2):    # Geyer pairs
        pair = acf[k] + acf[k+1] if k+1 < len(acf) else acf[k]
        if pair <= 0: break
        s += pair
    return n / (1 + 2*s)

print(f"ESS = {ess(x[1000:]):.0f} / 199000")

Example 8.7 — Reading an experiment (numbers) On the mixture above with s=4 and n=2\times10^5, the code (seed 0) prints an acceptance rate \approx 0.32, an empirical mean \approx -0.003 (exact value 0) and \mathrm{ESS} \approx 20\,600 out of 199 000.

The chain switches mode about every 10 iterations (a switch: passing from x < -1 to x > 1 or back). This large step rejects two proposals in three, yet it mixes well, because it jumps across the gap between the modes.

The 0.234 target of Definition 8.5 is a limit for product targets in growing dimension (Roberts, Gelman and Gilks, 1997), and 0.44 is the optimum for a one-dimensional Gaussian (Gelman, Roberts and Gilks, 1996). Neither covers a bimodal target, where the right scale is the one that crosses the gap.

With s = 0.7: acceptance \approx 0.71, but mode trapping. The chain stays in one mode for about 1 300 iterations on average (about 150 switches in 2\times10^5 steps, over 10 independent runs).

Batch means give \mathrm{ESS} \approx 200. The code’s estimator, which truncates the autocorrelations at lag 200, reports about 600: a truncated sum underestimates \tau when the chain mixes this slowly.

Two chains started in opposite modes give \hat R \approx 1.5 after 1 000 iterations and still \approx 1.2 after 2 000 (medians over 200 pairs); with s = 4, \hat R \approx 1.00 after 1 000. Diagnosis: a high acceptance rate proves nothing; run several overdispersed chains (Gelman et al., Bayesian Data Analysis, in the References).

9. Langevin dynamics and generative models

Random-walk proposals explore a high-dimensional space slowly because they ignore the shape of the target. Langevin dynamics follows the gradient of the log-density toward high-probability regions, while noise keeps it exploring.

This chapter shows that the target is invariant for the continuous dynamics, computes the bias of its discretization (ULA), and explains why the same equation drives score-based generative models.

Definition 9.1 — Overdamped Langevin diffusion Let U : \mathbb{R}^d \to \mathbb{R} (the potential) be \mathcal{C}^1, with e^{-U} \in L^1. The Langevin diffusion is the SDE dX_t = -\nabla U(X_t)\,dt + \sqrt{2}\,dW_t, where (W_t) is a d-dimensional Brownian motion.

Its invariant distribution (if it exists: this is the case if U is confining, e.g. U(x) \geq a\|x\| - b) is \pi(x) = \frac{e^{-U(x)}}{\int e^{-U}\,d\lambda}, the Gibbs distribution associated with U.

In ML, one rather writes U = -\log \pi: the drift -\nabla U = \nabla \log \pi is the score — a central quantity in generative models (see the Multimodal GenAI module, chapter 3).

Proposition 9.2 — \pi invariant for the Langevin diffusion (proved) For every test function \varphi \in \mathcal{C}^\infty_c and X \sim \pi: \mathbb{E}[\mathcal{A}\varphi(X)] = 0, where \mathcal{A}\varphi = -\nabla U \cdot \nabla \varphi + \Delta \varphi is the generator of the diffusion. This characterizes invariance (expectations are preserved along the trajectories).

Proof. With \pi = e^{-U}/Z and d\pi = Z^{-1}e^{-U(x)}dx, integrations by parts (the boundary terms vanish, \varphi being compactly supported): \int (\Delta\varphi)\,e^{-U}\,dx = -\int \nabla\varphi \cdot \nabla(e^{-U})\,dx = \int \nabla\varphi \cdot \nabla U\; e^{-U}\,dx, using \nabla(e^{-U}) = -(\nabla U)\,e^{-U}.

Substituting: Z\,\mathbb{E}_\pi[\mathcal{A}\varphi] = \int \big[-\nabla U\cdot\nabla\varphi + \Delta\varphi\big]\,e^{-U}dx = \int \big[-\nabla U\cdot\nabla\varphi + \nabla U \cdot \nabla\varphi\big]e^{-U}dx = 0. ∎

Direct check in the Gaussian case U(x) = \|x\|^2/2: the diffusion is an Ornstein-Uhlenbeck diffusion dX_t = -X_t dt + \sqrt2\,dW_t, and \mathcal{N}(0,I_d) is stationary (ch. 7, Example 7.5).

Definition 9.3 — ULA and MALA The Euler-Maruyama discretization with step \gamma > 0 gives the ULA algorithm (unadjusted, without correction):

Key result — the ULA update X_{k+1} = X_k - \gamma\,\nabla U(X_k) + \sqrt{2\gamma}\,Z_{k+1}, \qquad Z_{k+1} \sim \mathcal{N}(0,I_d).

ULA is a biased Markov chain: its limiting distribution \pi_\gamma differs from \pi (an \mathcal{O}(\gamma) gap).

MALA adds a Metropolis-Hastings step (Def. 8.1) with the Gaussian proposal above, removing the bias exactly (at the price of rejections); the bias/cost trade-off is the subject of the work described in chapter 10.

Example 9.4 — The ULA bias computed exactly (Gaussian case) For \pi = \mathcal{N}(0,1) (U(x)=x^2/2): X_{k+1} = (1-\gamma)X_k + \sqrt{2\gamma}Z_{k+1} — an AR(1) (Example 7.5). Its stationary distribution is \mathcal{N}\big(0,\ \sigma_\gamma^2\big) with \sigma_\gamma^2 = \frac{2\gamma}{1-(1-\gamma)^2} = \frac{2}{2-\gamma} \;\xrightarrow[\gamma \to 0]{}\; 1.

Numbers:

  • \gamma = 0.5 \Rightarrow \sigma_\gamma^2 = 1.33 (bias +33%);
  • \gamma = 0.1 \Rightarrow 1.053 (+5%);
  • \gamma = 0.01 \Rightarrow 1.005 (+0.5%).

The variance bias is \gamma/(2-\gamma) \approx \gamma/2: halving the bias doubles the number of iterations needed to reach a given region — paper [1] of chapter 10 precisely quantifies this trade-off (explicit convergence speed in \gamma, d, and the target error).

Theorem 9.5 — Non-asymptotic guarantees for ULA (statement, [1]-[2]) If U is L-smooth and m-strongly convex, Durmus & Moulines (2017, 2019) show that after k iterations with a small enough step \gamma, in total variation and in Wasserstein distance W_2 (see the Optimal Transport module, chapter 2), W_2\big(\mathrm{law}(X_k),\,\pi\big) \;\leq\; \mathcal{O}\!\Big(e^{-k\gamma m/2}\,\sqrt{d/m} + \frac{L}{m}\sqrt{\gamma d}\Big) \quad\text{(orders of magnitude, from the mode as starting point)}, that is, exponential decay toward a bias plateau proportional to \sqrt\gamma; with decreasing steps, ULA converges (ergodicity) but with degraded rates.

These bounds, explicit in the dimension d, ground the modern analysis of high-dimensional sampling (ch. 10).

Proposition 9.6 — The score / generative models connection Diffusion-based generative models (see the Multimodal GenAI module, chapter 3; Deep Learning module, chapter 9, for VAE/GAN) learn a family of scores s_\theta(x,t) \approx \nabla_x \log p_t(x) of the noised versions p_t of the data.

The noise index follows the convention of the diffusion pages of the site: t = 0 is the data, and larger t means more noise, the last level being almost pure Gaussian noise.

Generation by annealed Langevin (Song and Ermon, 2019) starts from white noise and runs the levels in decreasing order of t, from the noisiest down to t = 1, with a few steps per level of X_{k+1} = X_k + \gamma_t\,s_\theta(X_k,t) + \sqrt{2\gamma_t}\,Z_{k+1} \qquad (\text{ULA, Def. 9.3, with potential } -\log p_t), and a step \gamma_t that shrinks with the noise level: decreasing noise plays the role of decreasing temperature in simulated annealing (Prop. 8.6).

The network learns the drift of the diffusion; the injected noise \sqrt{2\gamma_t}\,Z does the rest. The quantities of this chapter — Euler bias, optimal step, noise calibration — are therefore the same tuning knobs as those of diffusion models.

import numpy as np
rng = np.random.default_rng(3)

def ula(gamma, n=200_000):             # target N(0,1): U(x) = x^2/2
    x = 3.0
    for k in range(n):
        x = x - gamma*x + np.sqrt(2*gamma)*rng.standard_normal()
        if k >= n//2:                  # ignore burn-in
            yield x

for g in (0.5, 0.1, 0.01):
    v = np.fromiter(ula(g), float)
    print(f"gamma={g:4.2f}  stationary var {v.var():.4f}"
          f"  theory {2/(2-g):.4f}")
# at gamma=0.01 the chain decorrelates in ~1/gamma steps: expect a few % of noise

def mala(gamma, n=200_000):            # same proposal + MH acceptance
    x, out = 3.0, []
    U, dU = lambda z: z*z/2, lambda z: z
    q = lambda a, b: -(b - a + gamma*dU(a))**2 / (4*gamma)   # log q(a -> b) + const
    for k in range(n):
        y = x - gamma*dU(x) + np.sqrt(2*gamma)*rng.standard_normal()
        loga = U(x) - U(y) + q(y, x) - q(x, y)   # log[pi(y) q(y->x)] - log[pi(x) q(x->y)]
        if np.log(rng.random()) < loga: x = y
        if k >= n//2: out.append(x)
    return np.array(out)

print(f"MALA gamma=0.5 : var {mala(0.5).var():.4f} (exact 1)")   # ~0.995

Why this chapter is the heart of the module The loop is closed: measure/integration (ch. 1) → convergence and errors (ch. 2) → simulation (ch. 3) → Monte Carlo estimation and importance sampling (ch. 4-5) → conditioning and Markov chains (ch. 6-7) → estimation along trajectories (ch. 8) → diffusion dynamics (ch. 9).

The score \nabla\log\pi is at once “the optimal drift for sampling” and “the object learned by generative models”: this double status, formalized by the convergence guarantees of the course instructors, is the exact articulation between this module and the Multimodal GenAI and Deep Learning modules.

The tuning questions — step, bias, stability — are the same levers there.

10. Research (Durmus): sampling in high dimension

This self-study chapter presents three papers of the course coordinator that give non-asymptotic guarantees for the Langevin algorithms of chapter 9.

Alain Durmus — research directions Alain Durmus (CMAP, École Polytechnique) works at the interface of probability/statistics/ML, on the non-asymptotic analysis of sampling methods and their applications to Bayesian inference and generative models. Three foundational papers literally structure chapters 8-9 of this module.

Paper 1 — “Non-asymptotic convergence analysis for the Unadjusted Langevin Algorithm” A. Durmus, É. Moulines, Annals of Applied Probability 27(3), 2017 — arXiv:1507.05021. Explicit, non-asymptotic bounds in total variation for ULA with constant and decreasing steps, with close attention to the dimension. They improve and extend the first bounds of this kind, due to Dalalyan (JRSSB, 2017; arXiv 2014).

Main result: exponential decay toward a step-dependent plateau. For a precision \varepsilon in total variation and a constant step, the number of iterations is of order d\log d\;\varepsilon^{-2} when U is strongly convex (outside a ball), and of order d^5\varepsilon^{-2} when U is only convex, up to factors in \log(1/\varepsilon) (Tables 1 and 2 of the paper).

It is the source of Theorem 9.5, and it made “bounds in (d, \varepsilon)”, started by Dalalyan, the standard way of comparing sampling algorithms.

Paper 2 — “High-dimensional Bayesian inference via the Unadjusted Langevin Algorithm” A. Durmus, É. Moulines, Bernoulli 25(4A), 2019 — arXiv:1605.01559. The “dimension-optimized” version: bounds in Wasserstein W_2 distance and in total variation, with a precise tracking of the dependence on d under strong log-concavity.

The paper also shows that when U is three times differentiable with a Lipschitz Hessian, the bias of the same ULA chain in W_2 drops from order \sqrt\gamma to order \gamma. It then studies weighted empirical averages along the chain (mean-square error and exponential deviation bounds for bounded functions), illustrated on Bayesian binary regression. This paper gives Example 9.4 its general framework: how to choose \gamma as d grows.

Paper 3 — “The Tamed Unadjusted Langevin Algorithm” N. Brosse, A. Durmus, É. Moulines, S. Sabanis, Stochastic Processes and their Applications 129(10), 2019 — arXiv:1710.05559. What can be done when \nabla U grows super-linearly (potentials that are not globally Lipschitz: steep double wells, logistic priors…)? Euler-Maruyama becomes explosive; the authors “tame” the drift (\nabla U divided by 1+\gamma\|\nabla U\|) and prove the convergence of TULA — a magnificent example of stability reasoning guided by non-asymptotic analysis. The name taming has become a whole family of algorithms.

Guiding thread for the student These three papers read in the order of the course: convergence of ULA (ch. 7, 8, 9); dimension and bias (ch. 4, 9); robustness to steep drifts (ch. 9). They underlie the modern literature on scores and diffusion models (see the Multimodal GenAI module, chapter 3), where the same questions — step, bias, stability, dimension — arise for drifts learned by a neural network.

Exercises

  1. ★ Tonelli and exact computation. Let U_1, U_2 be i.i.d. \mathcal{U}[0,1]. Writing \mathbb{E}[Y] = \int_0^1 \mathbb{P}(Y > t)\,dt for Y \geq 0 (layer-cake formula), compute \mathbb{E}[\min(U_1,U_2)] then \mathbb{E}[|U_1 - U_2|] via a double integral (Fubini, nonnegative or integrable function).

    Solution. \mathbb{P}(\min > t) = (1-t)^2 so \mathbb{E}[\min] = \int_0^1 (1-t)^2 dt = \tfrac13. For the difference: \mathbb{E}|U_1-U_2| = 2\int_0^1\!\!\int_0^{u_1}(u_1-u_2)\, du_2\,du_1 = 2\int_0^1 \tfrac{u_1^2}{2}du_1 = \tfrac13 (the factor 2 by symmetry of the two half-triangles); check via layers: \mathbb{P}(|U_1-U_2| > t) = (1-t)^2, same integral.

  2. ★ Walk on the triangle, then on the square. A random walk jumps uniformly to one of the two other vertices of a triangle, so its matrix is P = (J - I)/2 with J the all-ones matrix. Show that the chain is irreducible and aperiodic, find its invariant distribution and the speed of convergence, and compare with the lazy version (stay in place with probability 1/2). Then do the same for the walk on the square (the 4-cycle).

    Solution. Triangle: the graph is connected, so the chain is irreducible. It returns to its start in 2 steps (A→B→A) and in 3 steps (A→B→C→A), and \gcd(2,3) = 1: aperiodic. P is symmetric and doubly stochastic, so the uniform distribution is invariant and reversible.

    The spectrum of P is \{1, -\tfrac12, -\tfrac12\}, and P^n = J/3 + (-\tfrac12)^n (I - J/3). From any vertex, \|P^n(x,\cdot) - \pi\|_{\mathrm{TV}} = \tfrac23\,(\tfrac12)^n . The lazy chain (I+P)/2 has spectrum \{1, \tfrac14, \tfrac14\} and distance \tfrac23(\tfrac14)^n: here laziness is not needed, and it even speeds convergence up.

    Square: each step changes the parity of the vertex, so returns take an even number of steps: period 2, eigenvalue -1, and P^n(x,x) = 0 for every odd n, so P^n(x,\cdot) does not converge. The lazy walk has spectrum \{1, \tfrac12, \tfrac12, 0\} and converges to the uniform distribution (Thm 7.3), at distance (\tfrac12)^{n+1} from any vertex.

  3. ★ Optimal rejection (full computation). We want to simulate the distribution with density f(x) \propto e^{-x^2/2}\mathbf{1}_{x>0} (truncated positive Gaussian) by rejection with the standard exponential proposal g(x) = e^{-x}\mathbf{1}_{x>0}. Compute the explicit M, the acceptance rate, and the expected number of proposals.

    Solution. f(x) = \sqrt{2/\pi}\,e^{-x^2/2}\mathbf{1}_{x>0}; \frac{f}{g} = \sqrt{2/\pi}\,e^{-x^2/2+x}, maximal at x=1 where the exponent equals 1/2.

    Hence M = \sqrt{2e/\pi} \approx 1.3155; rate = 1/M \approx 76\% — the same constants as Example 3.3 (no coincidence: by symmetry, drawing the absolute value of a truncated N(0,1) is equivalent to the symmetric Gaussian/Laplace problem); expected number of trials = M \approx 1.32.

  4. ★ Gaussian degeneracy of IS. Redo the computation of Prop. 5.2: show \mathbb{E}_g[w^2] = e^{\mu^2} for f=\mathcal{N}(0,1), g=\mathcal{N}(\mu,1), deduce \mathrm{ESS}/n = e^{-\mu^2}, then comment on the d-dimensional case with a proposal centered at \mu\mathbf{1}.

    Solution. w^2 = e^{-2\mu Y + \mu^2} and \mathbb{E}_g[e^{tY}] = e^{t\mu + t^2/2} with t = -2\mu gives \mathbb{E}_g[e^{-2\mu Y}] = e^{-2\mu^2+2\mu^2} = 1, hence \mathbb{E}_g w^2 = e^{\mu^2}.

    In d product dimensions, \mathbb{E}w^2 = e^{d\mu^2}: \mathrm{ESS}/n = e^{-d\mu^2} — for \mu = 0.5 and d = 50, e^{-12.5} \approx 3.7\times10^{-6}: one million draws yield ~4 effective points.

  5. ★ ULA on a Gaussian (proof to complete). For \pi = \mathcal{N}(0,1), show that the stationary distribution of the AR(1) X_{k+1} = (1-\gamma)X_k + \sqrt{2\gamma}Z_{k+1} is \mathcal{N}(0, 2/(2-\gamma)) (stationary variance computation), deduce the relative bias of the variance and the step needed for a bias < 1%.

    Solution. The stationary variance satisfies (independence of the innovations) \sigma^2_\infty = (1-\gamma)^2\sigma^2_\infty + 2\gamma, \quad \text{so} \quad \sigma^2_\infty = 2\gamma/(\gamma(2-\gamma)) = 2/(2-\gamma). Relative bias = \gamma/(2-\gamma) \approx \gamma/2; < 1% requires \gamma < 0.02. Generalization (bonus question): in d isotropic dimensions, same computation per axis; see paper [3] of ch. 10 (tamed ULA) for drifts that are not globally Lipschitz.

  6. ★★ Control tower. Prove the tower property in the case \mathcal{H} = \sigma(Y), \mathcal{G} = \sigma(Y,Z) discrete: verify point by point the tower identity by summing over the values of Z: \mathbb{E}[\mathbb{E}[X \mid Y,Z] \mid Y] = \mathbb{E}[X \mid Y]. Recover the law of total probability. Hint. Use Definition 6.1 with A = \{Y = y\} and the partition \{Y=y\} = \bigcup_z \{Y=y, Z=z\}.

    \mathbb{E}[X \mid Y=y] = \sum_z \mathbb{E}[X \mid Y=y, Z=z]\,\mathbb{P}(Z=z \mid Y=y): the average of conditional averages, weighted by the distribution of Z given Y. Trivial \mathcal{H} case: \mathbb{E}[\mathbb{E}[X\mid Y]] = \mathbb{E}[X] = total probability.

  7. ★★ MH-independence. Establish the acceptance probability of the independence sampler (q(x,\cdot) = g) and verify detailed balance directly. What happens when g has lighter tails than \pi (e.g. g Gaussian, \pi Cauchy)? Hint. Redo the proof of Thm 8.2 with \rho(x,y) = \pi(x)g(y).

    \alpha(x,y) = \min\big(1, \tfrac{\pi(y)g(x)}{\pi(x)g(y)}\big). Detail: \pi(x)g(y)\,\alpha(x,y) = \min(\pi(x)g(y), \pi(y)g(x)) is symmetric.

    If g decays faster than \pi, the ratio \pi/g is unbounded: rejections dominate in the tails, the chain sticks to its states and is no longer geometrically ergodic — golden rule: heavier tails for the proposal.

  8. ★★ ESS and weights. Show that for normalized weights w_1,\dots,w_n > 0, \bar w_i = w_i/\sum_j w_j, the quantity 1/\sum_i \bar w_i^2 \in [1,n] (participation index) coincides with the definition \mathrm{ESS} = n/(1+\mathrm{cv}^2) in expectation, and interpret the two extremes.

    Solution (sketch). Expanding \sum_i \bar w_i^2 to first order around the mean weights, \mathbb{E}\big[\sum_i \bar w_i^2\big] \approx \frac1n\big(1 + \mathrm{cv}^2\big), hence the identification with the definition \mathrm{ESS} \approx 1/\sum_i \bar w_i^2.

    Extremes: equal weights (\bar w_i = 1/n) give \sum \bar w_i^2 = 1/n, i.e. \mathrm{ESS} = n (all draws count); if a single particle carries all the weight, \sum \bar w_i^2 = 1 and \mathrm{ESS} = 1. This index is the diagnostic displayed by all SMC software.

Projects and assessment

Official assessment: “Exam and Lab” — the SynapseS 2026–2027 sheet of APM_51056_EP gives a numerical grade out of 20, a resit (the better of the two grades counts) and acquisition at 10/20, for the degrees it lists. The LLGA lists do not include this unit, so no LLGA rule applies. Everything below is a proposal sized for a 36 h course: solo subjects of about 20 h, group subjects of 25–30 h per member, a three-hour written exam and a rubric.

The projects exercise two master objectives: O1 (foundations: Monte Carlo error bars, the LLN and the CLT, convergence of Markov chains) and O2 (generative modelling theory: MCMC, Langevin dynamics, the score). The score-based subject continues in Multimodal Generative AI, and the molecule subject adds O4 (graph-structured data) through Graph ML. All of them train O7 (hands-on practice): every sampler is first checked on a target with a known answer, and every number comes with its error bar.

Solo projects

  1. [Solo · ≈ 20 h] Diagnosing MCMC on multimodal targets. Which diagnostics catch a sampler that has not converged, which ones are fooled, and how does the answer change with the dimension?
    • Implement: random-walk MH, MALA and parallel tempering on mixtures of two well-separated Gaussians in dimension 2, 10 and 50; acceptance rate, ESS by Geyer’s initial sequence and by batch means, \hat R over 4 overdispersed chains, mode-switching rate.
    • Paper study: Vehtari, Gelman, Simpson, Carpenter and Bürkner, “Rank-normalization, folding, and localization: an improved \hat R for assessing convergence of MCMC”, Bayesian Analysis 16(2), 2021 — compare the classic and the rank-normalized \hat R on the same chains.
    • Reproduce: Example 8.7 from its code, and the MALA check of ch. 9 (stationary variance close to 1 at \gamma = 0.5, against 1.33 for ULA).
    • Deliverables: code, 4–6 page report ending with a one-page diagnostic checklist, 10-minute talk. Chapters: ch. 7, 8, 9.
    • Success criterion: over 50 replications, the 95 % MCMC intervals cover the exact mean at least 90 % of the time whenever the checklist says “converged”; the report shows one case where ESS looks fine and \hat R does not.
  2. [Solo · ≈ 20 h] Rare events and the curse of dimension for importance sampling. How small a probability can crude Monte Carlo, exponential tilting and the cross-entropy method estimate, and how does a mismatched proposal break importance sampling as the dimension grows?
    • Implement: the three estimators for \mathbb{P}(Z > a) with a = 3 to 6, then for the loss of a portfolio of d correlated Gaussian factors exceeding a high quantile (closed form, for checking); the ESS of the proposal \mathcal{N}(\mu\mathbf{1}, I_d) against \mathcal{N}(0, I_d) for d up to 50.
    • Prove: \mathrm{ESS}/n = e^{-d\mu^2} (Prop. 5.2), and the second moment of the tilted estimator with g = \mathcal{N}(\mu, 1), which is e^{\mu^2}\,\Phi(-(a+\mu)).
    • Paper: de Boer, Kroese, Mannor and Rubinstein, “A tutorial on the cross-entropy method”, Annals of Operations Research 134, 2005.
    • Deliverables: code, 4-page report, 10-minute talk. Chapters: ch. 2, 4, 5.
    • Success criterion: every estimate comes with a CLT interval, and over 100 replications the 95 % intervals of the methods that work cover the exact value at least 90 % of the time. With n = 10^5 draws, the measured ESS follows e^{-d\mu^2} within 20 % while e^{-d\mu^2} \geq 0.15; beyond, the report shows that it becomes over-optimistic and explains why (the error on \sum_i w_i^2 involves \mathbb{E}_g[w^4] = e^{6d\mu^2}). The report states where each method fails.

Group projects

  1. [Group of 3 · ≈ 25 h each] From ULA to score-based generation on toy data. Does the step-size bias of ULA (ch. 9) predict the quality of samples generated with a learned score, and what do the number of noise levels and of steps per level change?
    • Paper study: Song and Ermon, “Generative modeling by estimating gradients of the data distribution”, NeurIPS 2019 — a noise-conditional score network sampled by annealed Langevin (Prop. 9.6).
    • Implement: a small MLP score network trained by denoising score matching on 2-D data (Swiss roll and two moons from scikit-learn, a mixture of 8 Gaussians on a circle), then annealed Langevin; ULA, MALA and tamed ULA (paper 3 of ch. 10) on known targets, including the steep double well U(x) = x^4/4 - x^2/2 in dimension 10 to 100.
    • Question to answer: why can MALA not correct a learned score? (A score network gives no log-density, so the Metropolis-Hastings ratio of Def. 8.1 cannot be computed.)
    • Split of work: A trains the score networks; B writes the samplers and checks them on known targets; C owns the metrics (sliced Wasserstein distance to held-out data, mode weights), the seeds and the report.
    • Link: Multimodal Generative AI, ch. 3 (denoising score matching, Theorem 3.4, annealed Langevin).
    • Deliverables: repository, 6-page report, 15-minute talk. Chapters: ch. 7, 8, 9, 10.
    • Success criterion: on the Gaussian target the samplers reproduce Example 9.4 within error bars; ULA diverges on the double well for large steps while tamed ULA does not; on the 8-Gaussian mixture, annealed Langevin recovers every mode with weight 1/8 \pm 0.03 over 5 seeds; on the two-mode mixture with weights 1/5 and 4/5 of Song and Ermon, Langevin at a single noise level gets the weights wrong and annealed Langevin does not.
  2. [Group of 3 · ≈ 30 h each] High-dimensional Bayesian logistic regression: ULA, MALA and Gibbs. At equal computing time, which sampler gives the most accurate posterior means, variances and predictive probabilities as the dimension grows? A paper study of Durmus and Moulines, “High-dimensional Bayesian inference via the Unadjusted Langevin Algorithm”, Bernoulli 25(4A), 2019 (paper 2 of ch. 10).
    • Data: German Credit (Statlog, OpenML id 31: 1,000 applicants, 20 attributes, one-hot encoded), and a synthetic design with d from 10 to 1,000 and known coefficients.
    • Implement: ULA and MALA with a Gaussian prior and a step scaled with d; the Pólya-Gamma Gibbs sampler of Polson, Scott and Windle (JASA, 2013), for example with the polyagamma package; a long MALA run as the reference posterior.
    • Measure: errors on posterior means and variances against the reference, ESS per second, held-out log-loss and calibration, and the ULA bias as \gamma varies (Theorem 9.5).
    • Split of work: A: ULA and step tuning; B: MALA and the reference chains; C: the Gibbs sampler and the predictive evaluation.
    • Deliverables: repository, 6-page report, 15-minute talk. Chapters: ch. 8, 9, 10.
    • Success criterion: every comparison is at equal wall-clock time, with error bars over 5 seeds; the report tests whether the ULA bias on posterior variances is linear in \gamma, as Example 9.4 predicts for a Gaussian, and says which sampler wins at d = 1{,}000 and why.
  3. [Group of 3 · ≈ 30 h each] Metropolis-Hastings over graphs for molecule design. Can a Markov chain on molecular graphs, cooled by simulated annealing, find molecules with a high property score that stay valid, new and diverse?
    • Paper study: Xie, Shi, Zhou, Yang, Zhang, Yu and Li, “MARS: Markov molecular sampling for multi-objective drug discovery”, ICLR 2021.
    • Data: ZINC250k, about 250,000 drug-like molecules selected by Gómez-Bombarelli et al. (ACS Central Science, 2018), as SMILES; RDKit for validity, QED and logP.
    • Implement: an energy U(G) equal to minus a property (QED, or a GNN predictor trained on ZINC) plus validity and size penalties; graph edits (add or delete an atom or a bond, change an atom type) with their reverse probabilities, so that the ratio of Def. 8.1 is exact; temperature schedules (Prop. 8.6).
    • Check: detailed balance of the edit kernel (Theorem 8.2) on a space of small graphs small enough to enumerate.
    • Split of work: A: graph edits and the proposal ratio; B: the property predictor, with Graph ML ch. 9 (graph generation) as background; C: schedules, diagnostics (trace and ESS of the energy) and evaluation.
    • Deliverables: repository, 6-page report, 15-minute talk. Chapters: ch. 7, 8.
    • Success criterion: on the enumerable space, visit frequencies match \pi (chi-squared test at 5 %); on ZINC, three schedules are compared on the mean QED, validity, novelty and diversity of their top 100 molecules, with error bars over 5 seeds.

Written exam (proposal)

Three hours, one handwritten A4 sheet and a basic calculator allowed; four independent questions. Use \Phi(-3) \approx 1.35\times10^{-3}, \Phi(-6) \approx 9.87\times10^{-10} and e^9 \approx 8\,103.

  1. Question (5 points). Two runs of random-walk Metropolis on the bimodal target of Example 8.7 report: run A, step 0.7, acceptance 0.71; run B, step 4, acceptance 0.32. A colleague prefers A “because it accepts more”. (a) What does each of the trace, the autocorrelation (or ESS) and \hat R detect? (b) Which run do you trust, and how do you check it? (c) Why is the 0.234 rule not the right guide here?

    Expected: (a) the trace shows mode trapping and drift; the autocorrelation gives \tau and the ESS, the variance inflation of the chain CLT (Prop. 8.4); \hat R compares overdispersed chains and reveals a mode that one chain has not visited. (b) B: it switches mode about every 10 iterations (ESS ≈ 20,000 against ≈ 200); check with at least 4 chains started in both modes, \hat R \approx 1 and mode weights near 1/2. (c) The rule comes from product targets in growing dimension; acceptance measures local moves, not crossings between modes.

  2. Question (6 points). Let p = \mathbb{P}(Z > 3) with Z \sim \mathcal{N}(0,1). (a) How many crude Monte Carlo draws give a 10 % relative standard error? (b) With the proposal g = \mathcal{N}(3,1), write the weight w and show that \mathbb{E}_g\big[w(Y)^2\,\mathbf{1}_{Y>3}\big] = e^{9}\,\Phi(-6).

    1. Deduce the number of draws for a 10 % relative standard error, and the 95 % interval returned by n draws.

    Expected:

      1. The relative standard error is \sqrt{(1-p)/(np)}, so n \approx 100(1-p)/p \approx 7.4\times10^4.
      1. w(y) = e^{-3y + 9/2}; then w^2\,\varphi(y-3) = e^{9}\varphi(y+3), and integrating over y > 3 gives e^9\,\Phi(-6).
      1. e^9\Phi(-6) \approx 8.0\times10^{-6}; subtracting p^2 \approx 1.8\times10^{-6} leaves a per-draw standard deviation \approx 2.5\times10^{-3}, that is 1.84 times p, so n \approx 100 \times 1.84^2 \approx 340 draws — about 220 times fewer.
    • The interval is \hat p \pm 1.96\,\hat\sigma/\sqrt n, with \hat\sigma the empirical standard deviation of the weighted indicators.
  3. Question (5 points). (a) On a finite space, prove that if \pi(x)P(x,y) = \pi(y)P(y,x) for all states, then \pi P = \pi. (b) Give an irreducible, aperiodic chain on three states whose invariant distribution is uniform but which is not reversible. (c) Prove that the Gibbs update of one coordinate is a Metropolis-Hastings step with acceptance probability 1.

    Expected:

      1. Sum the identity over x and use \sum_x P(y,x) = 1.
      1. The biased rotation P(x, x+1) = 2/3, P(x, x-1) = 1/3 (indices mod 3) is doubly stochastic, so the uniform law is invariant; it returns in 2 and 3 steps, so it is aperiodic; but \pi_1 P_{12} = 2/9 \neq 1/9 = \pi_2 P_{21}.
      1. As in Prop. 8.3: with the full conditional as proposal and y_{-i} = x_{-i}, the factorization \pi(x) = \pi(x_{-i})\,\pi(x_i \mid x_{-i}) makes the ratio equal to 1.
  4. Question (4 points). Let \pi = \mathcal{N}(0, \sigma^2), so U(x) = x^2/(2\sigma^2). (a) Write the ULA recursion and find the steps for which it is stable. (b) Prove that its stationary variance is \sigma^2/(1 - \gamma/(2\sigma^2)). (c) In \mathbb{R}^d with independent coordinates of variances \sigma_1^2 \geq \dots \geq \sigma_d^2, explain why the number of iterations grows like \sigma_1^2/\sigma_d^2.

    Expected:

      1. The recursion is an AR(1), X_{k+1} = \big(1 - \gamma/\sigma^2\big)X_k + \sqrt{2\gamma}\,Z_{k+1}, stable if and only if 0 < \gamma < 2\sigma^2.
      1. The stationary variance v solves v = (1-\gamma/\sigma^2)^2 v + 2\gamma, which gives the formula (Example 9.4 when \sigma = 1).
      1. Stability and a small bias on the narrowest coordinate force \gamma \lesssim \sigma_d^2; the widest coordinate forgets its start like (1-\gamma/\sigma_1^2)^k, so it needs about \sigma_1^2/\gamma iterations — the ratio L/m of Theorem 9.5.

Total: 5 + 6 + 5 + 4 = 20 points.

Grading rubric (proposal)

Criterion Weight What earns the marks
Correctness of derivations and samplers 30 % Proofs are complete; every sampler is first validated on a target with a known answer (Gaussian, enumerable space, closed-form tail)
Diagnostics and error bars 25 % Every estimate has a CLT or MCMC interval; ESS, \hat R and traces are reported from several overdispersed chains and seeds
Experimental design 15 % Methods are compared at equal cost (draws or wall-clock time); the question and the metrics are fixed before the runs
Report and talk 20 % Clear figures, assumptions stated next to each conclusion, failures and negative results reported, time limit respected
Reproducibility and teamwork 10 % One command reruns the results from fixed seeds; data and paper versions are cited; for groups, a visible split of the work

References