---
tag: MKHF449E22
kind: concept
name: Metropolis–Hastings algorithm
msc: [65C05, 60J22, 65C40]
specializes: [ZGNBR2SPZ0]
sources:
  - url: https://en.wikipedia.org/wiki/Metropolis%E2%80%93Hastings_algorithm
same_as:
  wikidata: Q910810
  wikipedia: Metropolis–Hastings algorithm
---

## Summary

The Metropolis–Hastings algorithm is a [[Markov chain Monte Carlo|ZGNBR2SPZ0]] method.
It turns an arbitrary proposal mechanism into a [[Markov chain|0G48PYM96Q]] with a prescribed stationary distribution $\pi$.
At each step a candidate move is proposed and then accepted or rejected with a probability chosen to enforce [[detailed balance|CTGN6CK1ZS]].
Only ratios $\pi(y)/\pi(x)$ enter, so the normalising constant of $\pi$ is never needed.

## Explanations

### L1 human

The chain sits at a state and suggests a new state at random.
If the new state is more likely under $\pi$, the move is usually taken; if it is less likely, the move is taken only sometimes.
Rejected moves keep the chain where it is.
This balance of moves up and down in probability makes the chain spend time in each state in proportion to $\pi$.
For instance, with a symmetric proposal and $\pi(y) = \pi(x)/2$, a move from $x$ to $y$ is accepted half the time.
