Metropolis algorithm (source code)

= Metropolis algorithm
{c}
{title2=$\alpha(x,y)=1\wedge\pi(y)/\pi(x)$}

The Metropolis algorithm is the symmetric-proposal case of the <Metropolis–Hastings algorithm>. At state $x$ with positive target density $\pi(x)$, propose $y$ from $q(x,\cdot)$ with $q(x,y)=q(y,x)$, and accept with probability
$$
\alpha(x,y)=\min\{1,\pi(y)/\pi(x)\}.
$$
Otherwise remain at $x$. A normalizing constant in $\pi$ cancels, which makes the method useful when a target distribution is known only up to scale.

The accepted probability flow is $\pi(x)q(x,y)\alpha(x,y)=q(x,y)\min\{\pi(x),\pi(y)\}$, symmetric in $x,y$. This proves <detailed balance> and hence invariance of the target under the usual kernel assumptions.

For two states with target masses $1/4,3/4$ and an always-flip proposal, moves from the first state are always accepted, while reverse moves are accepted with probability $1/3$. The rejection probability creates holding at the second state. Target invariance alone does not prove convergence from every start; irreducibility and appropriate periodicity conditions matter. An asymmetric proposal requires the Hastings proposal-density correction.