MIT 6.1220 — Lecture 21

Random Walks (Part II)

Problem. (Card Shuffling) Among all 52!52! permutations of a deck of cards, pick one at random.

The challenge is that we cannot just define a map f:{1,2,,52!}{permutations}f: \{1, 2, \dots, 52!\} \to \{\text{permutations}\}, because 52!52! is huge.

Meta-Algorithm. To efficiently sample from a very large probability distribution π\pi,
just define a Markov chain that converges to π\pi as tt \to \infty.

Solution. (Card Shuffling) In this particular case: riffle-shuffle seven times.

To clarify the rules a little:

Problem. (Independent Set) Given a graph GG (e.g. a hexagonal lattice), sample an independent set of vertices. In the language as above, we have F(S):=1[S is independent]F(S) := \mathds{1}[S \text{ is independent}]. So F(x)F(x) is computable, but yF(y)\sum_{y} F(y) is not.

Solution. (Independent Set) Start with an independent set II. Repeat the following process.

Process. Pick a vertex vVv \in V uniformly at random.
If vIv \in I, then remove vv with probability 12\frac{1}{2}.
If v∉Iv \not \in I and vv can be added to II, then add vv with probability 12\frac{1}{2}.

We claim that π\pi is the unique stationary distribution of WW, and that π0WTπ\pi_0W^T \to \pi as TT \to \infty.

Proof: The desired (uniform) distribution π\pi is stationary with respect to WW. This is because WW is symmetric:

For all II, we have W(II)=12V or W(II)=0.\text{For all } I \neq I', \text{ we have } W(I \to I') = \frac{1}{2 |V|} \text{ or } W(I \to I') = 0.

It thus remains to check convergence and uniqueness.

Therefore, π\pi must be the stationary distribution of WW.   \blacksquare

Remark. The constant 12\frac{1}{2} is necessary to encourage “mixing” and avoid periodicity.

We'd like to generalize the approach from above. More specifically,

Problem. Given F(x)F(x), determine a Markov chain which converges to the distribution π(x):=F(x)yF(y)\pi(x) := \frac{F(x)}{\sum_y F(y)}.

The tricky part is guaranteeing that the π\pi we want truly is stationary with respect to WW. Here's how.

Definition (Metropolis-Hastings Algorithm). Say our target distribution is π\pi, and let QQ be any Markov chain. We don't know π\pi, but we do know FF, so we may create a new Markov chain like so:

W(xy):=Q(xy)min{1, F(y)F(x)Q(yx)Q(xy)}acceptance factor    and    W(xx)=1yxW(xy).W(x \to y) := Q(x \to y) \cdot \underbrace{\min \left \{ 1, \ \dfrac{F(y)}{F(x)} \cdot \dfrac{Q(y \to x)}{Q(x \to y)} \right \}}_{\text{acceptance factor}} ~~~ \text{ and } ~~~ W(x \to x) = 1 - \sum_{y \neq x} W(x \to y).

Remark. When the target distribution π\pi is uniform, Metropolis-Hastings returns the Markov chain

W(xy)=W(yx)=min{Q(xy), Q(yx)}.W(x \to y) = W(y \to x) = \min \{ Q(x \to y), \ Q(y \to x)\}.

The claim, of course, is that our target π\pi is always stationary with respect to this choice of WW.

Remark. This new Markov chain is equivalent to the following:

The acceptance factor, in a sense, adjusts our generic Markov chain QQ to account for the weights FF desired.

To see the motivation and validity for this selection of WW, we introduce the notion of reversible Markov chains.

Definition (Reversible). Informally, a Markov chain WW is reversible if it “looks the same” viewed forward and backwards.

Mathematically, this reads P(xy)=P(yxx)P(x \to y) = P(y \to x \mid \bullet \to x), for all pairs of states (x,y)(x, y) and all times tt. However, the RHS depends on the probability distribution XtX_t of states.

What distribution XtX_t should we choose? The stationary distribution π\pi, naturally. Then:

P(xy)=P(yxx)     W(xy)=π(y)W(yx)π(x)\begin{align*}P(x \to y) = P(y \to x \mid \bullet \to x) \implies ~ W(x \to y) = \dfrac{\pi(y) \cdot W(y \to x)}{\pi(x)}\end{align*}

The above is detailed balance: for all states x,yx, y, we have π(x)W(xy)=π(y)W(yx)\pi(x) W(x \to y) = \pi(y) W(y \to x).

Example. All random walks on undirected weighted graphs are reversible.

The choice to pick the stationary distribution π\pi for our XtX_t was not arbitrary.

Claim. If WW is a Markov chain and π\pi is a distribution satisfying detailed balance, then π\pi must be stationary.

Proof: Intuitively, detailed balance locally says that the flow along xyx \to y equals the flow along yxy \to x. Meanwhile, stationary globally says that the net flow out of any state xx is zero.

The local condition implies the global one.   \blacksquare

Claim. In Metropolis-Hastings, the target distribution π\pi is stationary with respect to WW.

Proof: The upshot of all these definitions is that it suffices to check π\pi satisfies detailed balance.

Suppose, WLOG, that the xyx \to y acceptance factor F(y)F(x)Q(yx)Q(xy)\frac{F(y)}{F(x)} \cdot \frac{Q(y \to x)}{Q(x \to y)} is less than 11. Then detailed balance says:

π(x)W(xy)=π(x)(Q(xy)F(y)F(x)Q(yx)Q(xy))=(π(x)F(y)F(x))Q(yx)=π(y)Q(yx).\pi(x) W(x \to y) = \pi(x) \cdot \left(Q(x \to y) \cdot \dfrac{F(y)}{F(x)} \cdot \dfrac{Q(y \to x)}{Q(x \to y)}\right) = \left(\pi(x) \cdot \dfrac{F(y)}{F(x)}\right) \cdot Q(y \to x) = \pi(y) \cdot Q(y \to x).

Meanwhile, the yxy \to x acceptance factor is 11, since its ratio is the reciprocal of the one above. So π(y)W(yx)=π(y)Q(yx)\pi(y) W(y \to x) = \pi(y) \cdot Q(y \to x) as well. So indeed, detailed balance is satisfied, and we win.   \blacksquare

Of course, Metropolis-Hastings doesn't do all the work—we still need to check for convergence, which requires checking recurrent components and periodicity of QQ.

Remark. Metropolis-Hastings isn't all that necessary, either. Our solution to Independent Set from earlier showed π(x):=F(x)yF(y)\pi(x) := \frac{F(x)}{\sum_y F(y)} was stationary by noting that π\pi was uniform and WW was symmetric.

Problem. (Graph Colorings) Given a graph GG, sample a valid coloring of its vertices with q>max{degv}+1q > \max\{\deg v\} + 1 colors, uniformly at random across all valid colorings.

Solution. (Graph Colorings) Begin with a graph coloring χ\chi. Repeat the following process.

Process. Pick a vertex vVv \in V uniformly at random, and a color c{1,2,,q}c \in \{1, 2, \dots, q\} uniformly at random.
If it will yield a valid graph coloring, then update χ(v)c\chi(v) \leftarrow c.

We claim the uniform distribution π\pi is the unique stationary distribution of WW, and that convergence holds.

Proof: To show that π\pi is a stationary distribution, just note that π\pi is uniform and WW is symmetric:

W(χ,χ)=W(χ,χ)={0if χ and χ are more than one vertex apart1Vqif χ and χ are exactly one vertex apartW(\chi, \chi') = W(\chi', \chi) = \begin{cases} 0 & \text{if $\chi$ and $\chi'$ are more than one vertex apart} \\ \dfrac{1}{|V| q} & \text{if $\chi$ and $\chi'$ are exactly one vertex apart} \end{cases}

It remains to show uniqueness. The main difficulty is connectivity.

Claim. For any pair of qq-colorings (χ,χ)(\chi, \chi'), there is a sequence of Markov chain transitions χχ\chi \to \chi'.

Proof: It suffices to find χχ\chi \to \chi'' for which (χ,χ)(\chi'', \chi') has fewer disagreements than (χ,χ)(\chi, \chi').

Pick some vertex vv for which χ(v)χ(v)\chi(v) \neq \chi'(v). If updating χ(v)χ(v)\chi(v) \leftarrow \chi'(v) is permitted, we're done.

Otherwise, χ(v)=χ(u)\chi'(v) = \chi(u) for some neighbor uvu \sim v. The key is that any such uu must also be a disagreeing vertex. Thus, we can recolor every such neighbor uu without creating any new disagreements; this is possible because q>deg(u)+1q > \deg(u) + 1.

So if χ(v)=χ(u)\chi'(v) = \chi(u) for some neighbor uvu \sim v, just recolor uu, reducing to the easy case.   \square

So connectivity holds. Aperiodicity does, too, as there are edges χχ\chi \to \chi. I'm convinced.   \blacksquare

Remark. This fails when q=max{degv}+1q = \max \{ \deg v \} + 1 because the Markov chain is disconnected. (Take G=K4G = K_4 and q=4q = 4.)