Detailed Balance and the Metropolis-Hastings Algorithm#
Learning Objectives#
Generalize Gibbs Sampling to the Metropolis-Hastings algorithm.
Connect Detailed Balance to preserving the target distribution.
Detailed Balance#
Last class, we considered the Gibbs sampler. We said, without any particular justification, that the Gibbs sampler preserves the target distribution. To show that this is true, we first observe that the Gibbs sampler obeys a property called “detailed balance”:
Any Markov chain that obeys detailed balance will have a stationary distribution that is equal to the target distribution, as
The Gibbs Sampler and Detailed Balance#
To see that the Gibbs sampler obeys detailed balance, we observe that the transition probability is given by
where \(x_k\) is the \(k\)’th variable. From the definition of detailed balance and of the conditional probability density, we have that
Using the properties of the delta function, this is equal to
which is in turn equal to \(\pi(y) p(x | y)\), so the Gibbs sampler obeys detailed balance.
The Metropolis-Hastings Algorithm#
The Metropolis-Hastings algorithm is a generalization of the Gibbs sampling algorithm. In the Metropolis-Hastings algorithm, we propose a new state \(x'\) from a proposal distribution \(q(x' | x)\), and then accept the new state with probability
If we accept the new state, we set \(x = x'\), otherwise we keep the old state.
(In many applications, people choose a symmetric proposal distribution, so that \(q(x' | x) = q(x | x')\). This makes evaluating this ratio easier.)
The transition probability for Metropolis Hastings is given by
To show that the Metropolis-Hastings algorithm obeys detailed balance, we consider two cases. If \(x' = x\), then the equation is trivially satisfied. If \(x' \neq x\), then the delta function is zero, and we have
Consequently, the Metropolis-Hastings algorithm obeys detailed balance. Note that if we set \(q(x' | x)\) to be the conditional distribution of the \(i\)’th variable given all the others, then the Metropolis-Hastings algorithm reduces to the Gibbs sampling algorithm.x