liveBook · Manning

Metropolis-hastings sampling

Metropolis-Hastings sampling is a Markov chain Monte Carlo method that proposes state changes and accepts or rejects them probabilistically to generate samples from a target distribution.

How 2 Manning books explain it

Fabulous Adventures in Data Structures and Algorithms

The Metropolis algorithm is a Markov chain Monte Carlo method that generates samples from a target distribution using proposed moves and acceptance probabilities based on relative weights.

How it is used
Generates samples from continuous posterior distributions when their non-normalized weight functions are available but direct sampling is not.
How deep it goes
Works through the acceptance rule and a one-dimensional C# implementation, while leaving multidimensional implementation aside.
Examples
Uses a weighted coin-flip transition, a two-peaked target histogram, and a coin-fairness posterior after nine heads in ten flips.
What you can do after
Build it from scratch in C# to sample a supplied target weight function or a continuous posterior.

Read how Fabulous Adventures in Data Structures and Algorithms explains metropolis-hastings sampling →

Machine Learning Algorithms in Depth

Metropolis-Hastings sampling is a Markov chain Monte Carlo technique that proposes state changes and accepts or rejects them using a probability designed to preserve the target distribution.

How it is used
Constructs samples from high-dimensional target distributions when direct sampling is difficult.
How deep it goes
Derives the acceptance correction from detailed balance and implements the complete proposal, evaluation, and decision loop.
Examples
Demonstrates a multivariate Gaussian-mixture target with a multivariate normal proposal and a Python sampler implementation.
What you can do after
Build a Metropolis-Hastings sampler from scratch and apply it to a multivariate Gaussian mixture.

Read how Machine Learning Algorithms in Depth explains metropolis-hastings sampling →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.