iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🎯

Statistics: Proof of the Detailed Balance Condition for the Metropolis-Hastings Algorithm

に公開

Introduction

While reading "Frontiers of Statistical Science 12: Computational Statistics II," I came across a section confirming that the detailed balance condition holds for the Metropolis-Hastings algorithm. It mentioned that the proof can be done in the same way as for the Metropolis algorithm. In this article, I will actually perform the calculations to verify this.

Background of the Discussion

It is known that the following theorem holds assuming the existence of states with irreducibility and aperiodicity, a transition probability function, and a stationary distribution. However, because this theorem is quite general, it is difficult to construct a Markov chain that satisfies it. Therefore, by adding the detailed balance condition as a constraint, we can construct a Markov chain that satisfies these requirements. Supplementary notes follow below.

Definition

Note that the state \mathbf{x} is a vector.

We define the transition probability function from \mathbf{x} to \mathbf{x}' as follows:

\begin{align} \pi(\mathbf{x} \to \mathbf{x'}) \end{align}

The stationary distribution is defined as follows:

\begin{align} &P(\mathbf{x}), \text{Where}\\ &\forall \mathbf{x}, P(\mathbf{x'}) = \sum_{\mathbf{x} \in \mathcal{X}} P(\mathbf{x}) \pi(\mathbf{x} \to \mathbf{x'}) \end{align}

Theorem

Assume that irreducibility and aperiodicity hold for the states and the transition probability function. That is, assume the following holds:

\begin{align} &\text{There exists some } M \text{ such that for any } \mathbf{x}, \mathbf{x}', \\ &\text{reaching } \mathbf{x}' \text{ from } \mathbf{x} \text{ is possible with finite probability after exactly } M \text{ transitions by } \pi. \end{align}

Assume that a stationary distribution P(\mathbf{x}) exists.

In this case, the following holds:

\begin{align} \text{As } m \rightarrow \infty, P_m(\mathbf{x}) \text{ converges to } P(\mathbf{x}) \text{ independently of the initial state } \mathbf{x}_0. \end{align}

Refer to the references for the proof.

Detailed Balance Condition

The detailed balance condition is a condition like the following:

\begin{align} \pi(\mathbf{x} \to \mathbf{x'}) P(\mathbf{x}) = \pi(\mathbf{x'} \to \mathbf{x}) P(\mathbf{x'}) \end{align}

Note that the constraint is stronger. In other words, if the above is satisfied, convergence to the stationary distribution is guaranteed by the aforementioned theorem.

Metropolis Algorithm and Metropolis-Hastings Algorithm

Definition

A new proposal distribution Q(\mathbf{x} \to \mathbf{x'}) is introduced. This distribution represents the probability of having \mathbf{x}' as a candidate for the transition target given \mathbf{x}.

Metropolis Algorithm

In the Metropolis algorithm, the following constraint is imposed:

\begin{align} Q(\mathbf{x} , \mathbf{x'}) = Q(\mathbf{x'} , \mathbf{x}) \end{align}
  1. Sample a candidate \mathbf{x}' from the proposal distribution Q(\mathbf{x}, \mathbf{x'}).
  2. Define the probability of accepting \mathbf{x}' as follows:
\begin{align} r = \min \left( 1, \frac{P(\mathbf{x'})}{P(\mathbf{x})}\right) \end{align}
  1. Determine whether or not to accept \mathbf{x}' according to r.
  2. If \mathbf{x}' is accepted, adopt \mathbf{x}' as the new state. Otherwise, adopt \mathbf{x} as the new state.

Metropolis-Hastings Algorithm

While an assumption was made about the proposal distribution in the Metropolis algorithm, the Metropolis-Hastings algorithm removes this assumption. To satisfy the detailed balance condition, the algorithm is modified as follows:

  1. Sample a candidate \mathbf{x}' from the proposal distribution Q(\mathbf{x}, \mathbf{x'}).
  2. Define the probability of accepting \mathbf{x}' as follows:
\begin{align} r = \min \left( 1, \frac{P(\mathbf{x'}) Q(\mathbf{x'} , \mathbf{x})}{P(\mathbf{x}) Q(\mathbf{x} ,\mathbf{x'})} \right) \end{align}
  1. Determine whether or not to accept \mathbf{x}' according to r.
  2. If \mathbf{x}' is accepted, adopt \mathbf{x}' as the new state. Otherwise, adopt \mathbf{x} as the new state.

Verification of Detailed Balance Condition in Metropolis Algorithm

We split the cases based on whether P(\mathbf{x'})>P(\mathbf{x}) holds. This is because if this inequality is true, r will always be 1.

Case where P(\mathbf{x'})>P(\mathbf{x})

\begin{align} &\pi(\mathbf{x} \to \mathbf{x}') = Q(\mathbf{x} , \mathbf{x'}) \\ &\pi(\mathbf{x}' \to \mathbf{x}) = \frac{Q(\mathbf{x}', \mathbf{x})P(\mathbf{x})}{P(\mathbf{x}')} \\ \end{align}
  • Transform equation (12) and substitute equation (11).
    Then,
\begin{align} \pi(\mathbf{x}' \to \mathbf{x}) &= Q(\mathbf{x} , \mathbf{x}') P(\mathbf{x}) / P(\mathbf{x}') \\ \pi(\mathbf{x}' \to \mathbf{x})&= \pi(\mathbf{x} \to \mathbf{x}') P(\mathbf{x})/P(\mathbf{x}') \\ \pi(\mathbf{x}' \to \mathbf{x})P(\mathbf{x}') &= \pi(\mathbf{x} \to \mathbf{x}') P(\mathbf{x}) \end{align}

Therefore, the detailed balance condition holds.

However, note the following. In equation (12), the transition source is \mathbf{x}' and the target is \mathbf{x}.

\begin{align*} r &= \min \left( 1, \frac{P(\mathbf{\text{Target}})}{P(\text{Source})}\right) \\ &= \min \left( 1, \frac{P(\mathbf{x})}{P(\mathbf{x}')}\right) \end{align*}

Case where P(\mathbf{x'})<P(\mathbf{x})

\begin{align} &\pi(\mathbf{x} \to \mathbf{x}') = Q(\mathbf{x} , \mathbf{x}') \frac{P(\mathbf{x}')}{P(\mathbf{x})} \\ &\pi(\mathbf{x}' \to \mathbf{x}) = Q(\mathbf{x}', \mathbf{x}) \\ \end{align}
  • Transform equation (16) and substitute equation (17).
    Then,
\begin{align} \pi(\mathbf{x} \to \mathbf{x}') &= Q(\mathbf{x}', \mathbf{x}) \frac{P(\mathbf{x}')}{P(\mathbf{x})} \\ \pi(\mathbf{x} \to \mathbf{x}')&= \pi(\mathbf{x}' \to \mathbf{x}) P(\mathbf{x}')/P(\mathbf{x}) \\ \pi(\mathbf{x} \to \mathbf{x}')P(\mathbf{x}') &= \pi(\mathbf{x}' \to \mathbf{x}) P(\mathbf{x}) \end{align}

Therefore, the detailed balance condition holds.

Detailed Balance Condition in Metropolis-Hastings Algorithm

We split the cases based on whether P(\mathbf{x'})Q(\mathbf{x}', \mathbf{x}) > P(\mathbf{x})Q(\mathbf{x}, \mathbf{x}') holds. This is because if this inequality is true, r will always be 1.

Case where P(\mathbf{x'})Q(\mathbf{x}', \mathbf{x}) > P(\mathbf{x})Q(\mathbf{x}, \mathbf{x}')

\begin{align} &\pi(\mathbf{x} \to \mathbf{x}') = Q(\mathbf{x} , \mathbf{x'}) \\ &\pi(\mathbf{x}' \to \mathbf{x}) = Q(\mathbf{x}', \mathbf{x}) \frac{P(\mathbf{x})Q(\mathbf{x}, \mathbf{x}')}{P(\mathbf{x}')Q(\mathbf{x}', \mathbf{x})} \\ \end{align}
  • Transform equation (21) and substitute equation (22).
    Then,
\begin{align} &\pi(\mathbf{x}' \to \mathbf{x}) = \frac{P(\mathbf{x})Q(\mathbf{x}, \mathbf{x}')}{P(\mathbf{x}')}\\ &\pi(\mathbf{x}' \to \mathbf{x})P(\mathbf{x}') = Q(\mathbf{x}', \mathbf{x})P(\mathbf{x}) \\ &\pi(\mathbf{x}' \to \mathbf{x})P(\mathbf{x}') = \pi(\mathbf{x}' \to \mathbf{x})P(\mathbf{x}) \end{align}

Therefore, the detailed balance condition holds.

Case where P(\mathbf{x'})Q(\mathbf{x}', \mathbf{x}) < P(\mathbf{x})Q(\mathbf{x}, \mathbf{x}')

\begin{align} &\pi(\mathbf{x} \to \mathbf{x}') = Q(\mathbf{x} , \mathbf{x}') \frac{P(\mathbf{x}')Q(\mathbf{x}, \mathbf{x}')}{P(\mathbf{x})Q(\mathbf{x}, \mathbf{x}')} \\ &\pi(\mathbf{x}' \to \mathbf{x}) = Q(\mathbf{x}', \mathbf{x}) \\ \end{align}
  • Transform equation (26) and substitute equation (27).
    Then,
\begin{align} &\pi(\mathbf{x} \to \mathbf{x}') = Q(\mathbf{x}' , \mathbf{x})P(\mathbf{x}')/P(\mathbf{x}) \\ &\pi(\mathbf{x} \to \mathbf{x}')P(\mathbf{x}) = \pi(\mathbf{x}' \to \mathbf{x})P(\mathbf{x}) \end{align}

Therefore, the detailed balance condition holds.

Summary

We have verified that the detailed balance condition holds for the Metropolis algorithm and the Metropolis-Hastings algorithm. In the future, I would like to work on implementing the Metropolis algorithm and the Metropolis-Hastings algorithm.

References

Discussion