Probabilistic & Bayesian ML

Markov chain Monte Carlo (MCMC)

/ MAR-kof chayn MON-tee KAR-loh /

Markov chain Monte Carlo is a method for drawing samples from a probability distribution you can't sample from directly — which is exactly the bind you're in with most Bayesian posteriors. Imagine wanting to explore a vast, fog-bound landscape where high ground means high probability, but you can't see it from above; all you can do is feel the slope under your feet. MCMC sends out a wanderer who takes random steps, more often climbing toward higher ground than down, and over a long walk the places the wanderer lingers map out the landscape's shape.

Concretely, the walker is at some point; it proposes a nearby random move; it accepts the move with a probability that favors more-probable destinations. The 'Markov' part means each step depends only on where it currently stands, not its whole history. The remarkable guarantee is that, if you let it walk long enough, the collection of places it visits is statistically indistinguishable from genuine samples of the target distribution — so you can compute averages, find credible intervals, and answer Bayesian questions just by tallying the trail.

Why it matters: MCMC made full Bayesian inference practical for complex, realistic models and is a cornerstone of modern statistics. Its honesty is in the fine print. It only matches the target after a 'burn-in' period whose length you must judge; consecutive samples are correlated, so a thousand steps are worth less than a thousand independent draws; and on tricky landscapes with separate peaks, the walker can get marooned on one hill and never report the others. Diagnosing whether the chain has truly explored everything ('convergence') is an unavoidable, sometimes thankless, part of the job.

Fitting a Bayesian model of how exercise affects blood pressure, with several interacting unknowns. The posterior over all of them at once is impossible to write down. MCMC walks through the space of parameter combinations for, say, 50,000 steps; you discard the first 10,000 as burn-in, then summarize the rest. The histogram of the kept samples is your posterior — its center the estimate, its spread the uncertainty.

MCMC turns an impossible-to-write posterior into a pile of samples you can simply count — after discarding the burn-in.

The dangerous failure mode is silent: a chain can look perfectly healthy while being trapped near one peak of a multi-peaked posterior, faithfully reporting a confident answer that misses entire regions of probability. Convergence diagnostics reduce this risk but can never fully prove the chain explored everything.

Also called
MCMC马尔可夫链蒙特卡洛馬可夫鏈蒙地卡羅马尔科夫链蒙特卡罗