Skip to content

NEW: Markov Chain Monte Carlo lecture#332

Merged
jstac merged 3 commits into
mainfrom
new/mcmc-lecture
Jun 5, 2026
Merged

NEW: Markov Chain Monte Carlo lecture#332
jstac merged 3 commits into
mainfrom
new/mcmc-lecture

Conversation

@jstac

@jstac jstac commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a new lecture, Markov Chain Monte Carlo (mcmc.md), placed immediately after stationary_densities in the Tools and Techniques section of the TOC.

The first part is a translation of an existing set of LaTeX notes on Bayesian inference via Metropolis-Hastings sampling; the second part adds a worked numerical example in JAX.

Theory (translation)

  • The Bayesian setting and why the unnormalized posterior is all we can evaluate
  • Markov kernels, density representations, and stationary distributions
  • Detailed balance and a proof that it implies stationarity
  • The ergodic theorem for Markov chains (irreducibility → LLN; aperiodicity → TV convergence)
  • The Metropolis-Hastings proposal/acceptance construction and its mixed transition kernel
  • A proof that the posterior is stationary for the MH kernel
  • Informal arguments for π-irreducibility and aperiodicity of the random walk sampler

Numerical example (JAX)

  • Gaussian model with conjugate prior; MH sampler built on jax.lax.scan + jit with explicit PRNG keys and the log acceptance ratio; draws validated against the closed-form posterior (moments agree to 3 decimals)
  • Ergodicity in action: running mean of a single trajectory (the LLN conclusion), and a vmap ensemble of 10,000 chains launched from a deliberately bad initial condition, whose cross-section densities march to the posterior (the TV-convergence conclusion) — visually echoing the density-sequence figures in stationary_densities
  • Losing conjugacy: 1-D quadrature ground truth, then a Student-t prior under prior-data conflict (heavy tails yield to the data) and a bimodal Gaussian-mixture prior with ambiguous data (posterior inherits the two-regime structure, with each mode pulled toward the evidence)
  • Exercises with dropdown solutions: proposal-scale tuning (trace plots + acceptance rates) and a sample-size sweep that resolves the bimodal posterior

Conventions

  • sphinx-proof directives throughout: 5 prf:definition, 4 prf:theorem (with prf:proof), 1 prf:example, 1 prf:algorithm — all labels prefixed mcmc_
  • One sentence per paragraph, per the style manual
  • Bold for defined terms, sentence-case headings, \mathrm{Uniform}, no \tag numbering
  • mystnb figure captions on main-text figures; none inside exercise/solution directives (PDF constraint)
  • JAX installed via !pip install jax following the precedent in dovis_accounting_mf.md, with a note admonition saying CPU is sufficient (the examples are small — no GPU needed)
  • Cross-link to the stationary_densities lecture; cites MeynTweedie2009 (already in quant-econ.bib)

Verification

  • Standalone jupyter-book build: no warnings beyond the standard !pip lexer notice; every {eq}/{prf:ref}/{ref}/{cite} target resolves; all 11 numbered directives render correctly
  • Full lecture executed end-to-end via jupytext --to py: clean run, all 7 figures inspected; seeds chosen so the figures match the narrative (sample mean lands near the true value; the first two mixture observations are genuinely ambiguous so the n=2 posterior is visibly bimodal)

🤖 Generated with Claude Code

Translation of mh_notes.tex (Bayesian inference via Metropolis-
Hastings) into a MyST lecture, placed after stationary_densities
in the TOC.

- Theorems, definitions, examples, proofs and the algorithm use
  sphinx-proof (prf:) directives with mcmc_-prefixed labels
- One sentence per paragraph throughout, per the style manual
- Bold for defined terms, sentence-case headings, \mathrm{Uniform},
  US spelling, no \tag equation numbering
- Cross-link to the stationary_densities lecture in the Markov
  kernels section
- Cites MeynTweedie2009 (already in quant-econ.bib)

Verified with a standalone jupyter-book build: no warnings, all
eq/prf/ref/cite targets resolve, all 11 directives render with
correct titles and numbering.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@netlify

netlify Bot commented Jun 4, 2026

Copy link
Copy Markdown

Deploy Preview for lustrous-melomakarona-3ee73e ready!

Name Link
🔨 Latest commit bbcf82b
🔍 Latest deploy log https://app.netlify.com/projects/lustrous-melomakarona-3ee73e/deploys/6a21e8bfcf86fb000812097c
😎 Deploy Preview https://deploy-preview-332--lustrous-melomakarona-3ee73e.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

…njugate priors

Extends the MCMC lecture with worked numerical sections:

- A numerical example: Gaussian model with conjugate prior; MH
  sampler in JAX (lax.scan, jit, log acceptance ratio, explicit
  PRNG keys); draws validated against the closed-form posterior
- Ergodicity in action: running mean of one trajectory (LLN part)
  and a vmap ensemble of 10,000 chains from a bad initial condition
  showing total variation convergence (echoing the density-sequence
  figures in stationary_densities)
- Losing conjugacy: quadrature ground truth on a grid, then
  (i) Student-t prior under prior-data conflict (heavy tails let
  the data overrule the prior), and (ii) a bimodal Gaussian mixture
  prior with ambiguous data (posterior inherits the two-regime
  structure, modes pulled toward the evidence)
- Exercises: proposal-scale tuning with trace plots; sample size
  sweep resolving the bimodal posterior

Seeds chosen so figures match the narrative (sample mean near the
true value; first two mixture observations genuinely ambiguous).

Verified by executing the full lecture via jupytext --to py
(all figures inspected) and a standalone jupyter-book build.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

@github-actions github-actions Bot temporarily deployed to pull request June 4, 2026 06:43 Inactive
Editorial edits by John: new introductory passage, tightened Overview
and roadmap, dθ' notation alongside μ(dθ') with explanatory note,
TV-convergence remark moved out of the ergodic theorem statement,
softened phrasing in the non-conjugate sections. Plus typo fixes on
top (Some/essence/produces/case, heavy-tailed double hyphen) and
trailing whitespace removal.

Ensemble figure: replace dates (10,...,499) with (1,5,15,25,40,80)
so the cross-section densities show the full journey to the
posterior instead of stacking on it; trim T_short to 100.

Parallel-chains restructure: scalar mh_chain is sequential and
wastes accelerators, so add a vmap-based mh_ensemble helper and run
all sampling workloads as 4,096 parallel chains (500 burn-in, pooled
to ~4M draws). Burn-in is now discussed explicitly and justified by
the TV-convergence result. Running mean uses a single ensemble row,
as the ergodic theorem requires; exercise 1 keeps single chains
(mixing is the point) and is self-contained. New passage ties the
pattern to NumPyro/BlackJAX: this is what runs under the hood of the
libraries used in later lectures.

Side effects: total runtime ~9s on CPU (was ~30s), posterior moments
match to 4 decimals, smoother histograms.

Verified by full execution via jupytext --to py with all seven
figures inspected; all references resolve.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot temporarily deployed to pull request June 4, 2026 21:16 Inactive
@jstac jstac merged commit f2447ab into main Jun 5, 2026
9 checks passed
@jstac jstac deleted the new/mcmc-lecture branch June 5, 2026 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant