DEV Community

Ethan Davis
Ethan Davis

Posted on

Markov Chain Monte Carlo: Theoretical Foundations

Adapted from an appendix of my MS thesis.

Markov Chain Monte Carlo

Almost as soon as computers were invented, they were used for simulation. Markov chain Monte Carlo (MCMC) was invested as Los Alamos, Metropolis et al (1953) simulated a liquid in equilibrium with its gas phase. Their tour de force was the realization that they did not need to simulate the exact dynamics, they only needed to simulate some Markov chain with the same equilibrium distribution. The Metropolis algorithm was widely used by chemists and physicists, but was not widely known among statisticians until after 1990. Hastings (1970) generalized the Metropolis algorithm, and simulations following his scheme are said to use the Metropolis-Hastings (MH) algorithm [1].

A special case of the MH algorithm was introduced by Geman et al (1984) discussing optimization to find the posterior mode rather than simulation. Algorithms following their scheme are said to use the Gibbs sampler. It took some time for the spatial statistics community to understand that the Gibbs sampler simulated the posterior distribution, thus enabling full Bayesian inference of all kinds. Gelfand et al (1990) made the wider Bayesian community aware of the Gibbs sampler, and then it was rapidly realized that most Bayesian inference could be done using MCMC, whereas very little could be done without MCMC. Green (1995) generalized the MH algorithm as much as it could be generalized [1].

Theoretical Foundations

A sequence X1,X2,X_ 1, X_ 2, \ldots of random elements of some set is a Markov chain if the conditional distribution of Xn+1X_ {n+1} given X1,,XnX_ 1,\ldots,X_ n depends on XnX_ n only. The set in which the XiX_ i take values is called the state space of the Markov chain. A Markov chain has stationary transition probabilities if the conditional distribution of Xn+1X_ {n+1} given XnX_ n does not depend on nn . This is the main kind of Markov chain of interest in MCMC. The joint distribution of a Markov chain is determined by the following [1].

  • The marginal distribution of X1X_ 1 called the initial distribution, and

  • The conditional distribution of Xn+1X_ {n+1} given XnX_ n called the transition probability distribution.

If the state space is finite or countable, written x1,,xn{x_ 1,\ldots,x_ n} , then the initial distribution can be associated with a vector λ=(λ1,,λn)\lambda=(\lambda_ 1,\ldots,\lambda_ n) defined by P(X1=xi)=λi\mathrm{P}(X_ 1=x_ i)=\lambda_ i for i=1,,ni=1,\ldots,n , and the transition probabilities can be associated with a matrix PP having elements pijp_ {ij} defined by P(Xn+1=xjXn=xi)\mathrm{P}(X_ {n+1}=x_ j \mid X_ n=x_ i) where i=1,,ni=1,\ldots,n and j=1,,nj=1,\ldots,n . When the state space is uncountable, we must think of the initial distribution and transition probability distribution as unconditional and conditional probability distributions [1].

A stochastic process is stationary if for every positive integer kk the distribution of the kk -tuple (Xn+1,,Xn+k)(X_ {n+1}, \ldots, X_ {n+k}) does not depend on nn . An initial distribution is said to be stationary, invariant, or equilibrium for some transition probability distribution if the Markov chain specified by this initial distribution and transition probability distribution is stationary. Stationarity implies stationary transition probabilities, but not vice versa. The Metropolis-Hastings-Green (MHG) algorithm constructs a transition probability distribution that preserves a specified equilibrium distribution [1].

A transition probability distribution is reversible with respect to an initial distribution if for its Markov chain X1,X2,X_ 1,X_ 2,\ldots , the distribution of pairs (Xi,Xi+1)(X_ i,X_ {i+1}) is exchangeable. Reversibility implies stationarity, but not vice versa. A reversible Markov chain has the same laws running forward and backward. That is, for any ii and kk , the distributions (Xi+1,,Xi+k)(X_ {i+1},\ldots,X_ {i+k}) and (Xi+k,,Xi+1)(X_ {i+k},\ldots,X_ {i+1}) are the same. All known methods for constructing transition probabilities that preserve a specified equilibrium are special cases of the MHG algorithm, and all elementary updates from the MHG algorithm are reversible [1].

A bit of compute code that makes a pseudorandom change to its state is an update mechanism. An update mechanism is elementary if it is not made up of parts that are themselves update mechanisms preserving the specified distribution. Suppose the specified distribution (the desired stationary distribution of the MCMC sampler) has unnormalied density hh . The Metropolis-Hastings update does the following [1]:

  • When the current state is xx , propose a move to yy , having conditional probability density given xx denoted q(x,y)q(x, y) .

  • Calculate the Hastings ratio

    r(x,y)=h(y)q(y,x)h(x)q(x,y). r(x,y) = \frac{h(y)q(y,x)}{h(x)q(x,y)}.
  • Accept the proposed move yy with probability

    a(x,y)=min(1,r(x,y)), a(x,y) = \min(1,r(x,y)),
    that is, the state after the update is yy with probability a(x,y)a(x,y) , and the state after the update is xx with probability 1a(x,y)1-a(x,y) .

For example, consider the probability density function h(x)h(x) is given by h(x)=g(x)g(u)duh(x) = \frac{g(x)}{\int_ {-\infty}^ {\infty}g(u)du} where we cannot or do not desire to solve the integral in the denominator analytically. Therefore, the distribution is only known up to some unknown constant: h(x)g(x)h(x) \propto g(x) . Notice that the ratio h(y)h(x)\frac{h(y)}{h(x)} from r(x,y)r(x,y) does not depend on the normalizing constant. The latter term q(y,x)q(x,y)\frac{q(y,x)}{q(x,y)} corrects for biases from the proposal distribution. The special case of the Metropolis-Hastings algorithm where the proposal distribution is symmetric meaning q(y,x)=q(x,y)q(y,x)=q(x,y) is referred to as the Metropolis algorithm [1].

The Metropolis-Hastings update is reversible with respect to hh , meaning that the transition probability that describes the update is an exact sampler of the specified distribution. If XnX_ n is the current state and YnY_ n is the proposal, we have Xn=Xn+1X_ n=X_ {n+1} whenever the proposal is rejected. The distribution of (Xn,Xn+1)(X_ n,X_ {n+1}) given rejection is exchangeable, and we must show that (Xn,Yn)(X_ n,Y_ n) is exchangeable given acceptance. That is, we must show that for any function ff that has expectation, we can interchange the arguments of ff [1].

E[f(Xn,Yn)a(Xn,Yn)]=f(x,y)h(x)a(x,y)q(x,y)dxdy=E[f(Yn,Xn)a(Xn,Yn)]. \mathbb{E}[f(X_ n,Y_ n)a(X_ n,Y_ n)] = \iint f(x,y)h(x)a(x,y)q(x,y)\mathrm{d}x\mathrm{d}y = \mathbb{E}[f(Y_ n,X_ n)a(X_ n,Y_ n)].

This follows if we can interchange xx and yy in h(x)a(x,y)q(x,y)h(x)a(x,y)q(x,y) . Only the set of xx and yy such that h(x)>0h(x)>0 , q(x,y)>0q(x,y)>0 , and a(x,y)>0a(x,y)>0 contribute to the integral or sum in the discrete case. These inequalities further imply that h(y)>0h(y)>0 and q(y,x)>0q(y,x)>0 . Thus r(y,x)=1r(x,y)r(y,x)=\frac{1}{r(x,y)} for all xx and yy . Suppose that r(x,y)1r(x,y) \leq 1 , so r(x,y)=a(x,y)r(x,y)=a(x,y) and a(y,x)=1a(y,x)=1 . Then we have the following [1].

h(x)a(x,y)q(x,y)=h(x)r(x,y)q(x,y)=h(y)q(y,x)=h(y)a(y,x)q(y,x). \begin{aligned} h(x)a(x,y)q(x,y) &= h(x)r(x,y)q(x,y) \\ &= h(y)q(y,x) \\ &= h(y)a(y,x)q(y,x).\end{aligned}

Conversely, suppose that r(x,y)>1r(x,y)>1 , so a(x,y)=1a(x,y)=1 and a(y,x)=r(y,x)a(y,x)=r(y,x) , and we have the following [1].

h(x)a(x,y)q(x,y)=h(x)q(x,y)=h(y)r(y,x)q(y,x)=h(y)a(y,x)q(y,x). \begin{aligned} h(x)a(x,y)q(x,y) &= h(x)q(x,y) \\ &= h(y)r(y,x)q(y,x) \\ &= h(y)a(y,x)q(y,x).\end{aligned}

References

  1. Brooks, Steve, Gelman, Andrew, Jones, Galin, Meng, Xiao-Li (Eds.) (2011) Handbook of Markov Chain Monte Carlo. Chapman and Hall/CRC.

Top comments (0)