# Randomized Algorithms (Spring 2010)/Random sampling

## Random sampling

Rejection sampling

### The Markov Chain Monte Carlo (MCMC) method

The MCMC method provide a very general approach to near uniform sampling. The basic idea of the method is as follows:

• Define a Markov chain whose state space is the sample space, and whose stationary distribution is the uniform distribution.
• Start the chain from an arbitrary state, run the Markov chain for a sufficiently long time, and return the current state.

Usually, the name "MCMC" refers to a class of methods for numerical computation or simulation by sampling via random walks. Here we use the name for the methods of sampling via random walks.

Consider the following problem:

Given an undirected graph ${\displaystyle G(V,E)}$ on ${\displaystyle n}$ vertices, uniformly sample an independent set of ${\displaystyle G}$.

By the MCMC method, we consider a Markov chain whose state space ${\displaystyle {\mathcal {I}}}$ is the space of all independent sets of ${\displaystyle G}$. Our sampling algorithm simply run the Markov chain for a sufficiently long time ${\displaystyle T}$, and return the current independent set at time ${\displaystyle T}$.

To guarantee that the returned independent set is nearly uniformly distributed, the Markov chain has to meet the following constraints:

• The chain converges (irreducible and aperiodic).
• The stationary distribution is uniform.

The running time of the algorithm is determined by: (1) the time complexity of a transition of a single step, and (2) the total number of steps ${\displaystyle T}$. Thus, to have an efficient algorithm, we have to also guarantee:

• The transition at each step of the chain is efficiently computable.
• The chain is rapid mixing.

We now focus on how to construct a Markov chain that converges to a uniform stationary distribution, and leave the discussion of mixing time to the next section.

Consider the problem of sampling an independent set of a graph ${\displaystyle G(V,E)}$. We consider an enormously large transition graph ${\displaystyle {\mathcal {G}}}$ whose vertex set is the state space ${\displaystyle {\mathcal {I}}}$. That is, every vertex of ${\displaystyle {\mathcal {G}}}$ is an independent set ${\displaystyle I}$ of ${\displaystyle G}$.

Irreducibility
Two independent sets ${\displaystyle I_{1},I_{2}\in {\mathcal {I}}}$ are adjacent to each other in the transition graph ${\displaystyle {\mathcal {G}}}$, if they differ from each other in just one vertex, formally, if ${\displaystyle I_{1}-I_{2}=\{v\}}$ or ${\displaystyle I_{2}-I_{1}=\{v\}}$ for some vertex ${\displaystyle v}$ of ${\displaystyle G}$. It is easy to see that the transition graph ${\displaystyle {\mathcal {G}}}$ is connected, since any independent set is connected to ${\displaystyle \emptyset \in {\mathcal {I}}}$ by a series of removals of vertices. The connectivity of the transition graph ${\displaystyle {\mathcal {G}}}$ implies the irreducibility of the Markov chain.
Aperiodicity
The Markov chain is aperiodic if it has nonzero loop probabilities, that is, if for some state ${\displaystyle I\in {\mathcal {I}}}$, the loop probability ${\displaystyle P(I,I)>0}$. Thus, the Markov chain is aperiodic if we make it lazy.

With irreducibility and aperiodicity, the chain converges to its stationary distribution. We now deal with the uniformity.

### The Metropolis algorithm

We know that the random walk on a regular graph has uniform distribution as its stationary distribution. We will show in general, how to make the stationary distribution uniform if the transition graph is irregular. This method is called the Metropolis algorithm. (In fact, the Metropolis algorithm transforms a Markov chain to a Markov chain with any required stationary distribution. Here, we only deal with the case that our goal is the uniform distribution.)

Consider a random walk on an undirected graph ${\displaystyle H}$, which is not necessarily regular. Let ${\displaystyle d}$ be the maximum degree of ${\displaystyle H}$.

 The Metropolis algorithm Let ${\displaystyle p\leq {\frac {1}{d}}}$. Consider a Markov chain with the transition matrix ${\displaystyle P_{u,v}={\begin{cases}p&{\mbox{if }}u\neq v{\mbox{ and }}u\sim v,\\0&{\mbox{if }}u\neq v{\mbox{ and }}u\not \sim v,\\1-p\cdot d_{u}&{\mbox{if }}u=v.\end{cases}}}$ The Markov chain is time-reversible, and the stationary distribution ${\displaystyle \pi }$ is the uniform distribution.
Proof.
 Because the graph ${\displaystyle H}$ is undirected, ${\displaystyle P}$ is symmetric. It follows that the uniform distribution is stationary. And ${\displaystyle \pi _{u}P_{u,v}=\pi _{v}P_{v,u}}$, thus the Markov chain is time-reversible.
${\displaystyle \square }$

The only magic that the Metropolis algorithm plays is having every edge has the same probability weight, therefore, in an undirected graph, the transition matrix is symmetric, thus the chain is time-reversible and the stationary distribution is uniform.

Back to our example of sampling an independent set of a fixed graph ${\displaystyle G(V,E)}$. The transition graph ${\displaystyle {\mathcal {G}}}$ is defined on the space ${\displaystyle {\mathcal {I}}}$ of all independent sets of ${\displaystyle G}$, and two independent sets are adjacent in ${\displaystyle {\mathcal {I}}}$ if they differ from each other in exact one vertex. This gives us a large undirected graph ${\displaystyle {\mathcal {G}}}$ whose vertices are independent sets of ${\displaystyle G}$. We consider the following random walk on ${\displaystyle {\mathcal {G}}}$.

 Random walk on ${\displaystyle {\mathcal {G}}}$ Given as the input an undirected graph ${\displaystyle G(V,E)}$: ${\displaystyle I_{0}=\emptyset \,}$. At step ${\displaystyle t}$, assuming that the current independent set is ${\displaystyle I_{t}}$, the ${\displaystyle I_{t+1}}$ is computed: choose a vertex ${\displaystyle v}$ uniformly at random from ${\displaystyle V}$; if ${\displaystyle v\in I_{t}}$ then ${\displaystyle I_{t+1}=I_{t}\setminus \{v\}\,}$; if ${\displaystyle v\not \in I_{t}}$ and ${\displaystyle \forall u\in I_{t},uv\not \in E}$, then ${\displaystyle I_{t+1}=I_{t}\cup \{v\}}$; otherwise, ${\displaystyle I_{t}=I_{t+1}\,}$.

For any independent sets ${\displaystyle I_{1},I_{2}}$ of ${\displaystyle G(V,E)}$, if ${\displaystyle |I_{1}\triangle I_{2}|>1}$, where ${\displaystyle \triangle }$ is the symmetric difference, then the transition probability is ${\displaystyle P(I_{1},I_{2})=0}$; if ${\displaystyle I_{1}\triangle I_{2}=\{v\}}$ for some ${\displaystyle v\in V}$, then with probability ${\displaystyle 1/|V|}$, ${\displaystyle v}$ is chosen and the transition from ${\displaystyle I_{1}}$ to ${\displaystyle I_{2}}$ occurs, thus ${\displaystyle P(I_{1},I_{2})=1/|V|}$. This corresponds to a random walk over ${\displaystyle {\mathcal {G}}}$ that each undirected edge of ${\displaystyle {\mathcal {G}}}$ has a probability weight of ${\displaystyle 1/|V|}$.

Due to the Metropolis algorithm, the Markov chain is time-reversible and has uniform distribution as its stationary distribution. We know this chain is irreducible (because ${\displaystyle {\mathcal {G}}}$is connected) and it is easy to see it is aperiodic (because it has nonzero self-loop probabilities). Therefore, running the chain for a sufficiently long time, the distribution will be close to the uniform distribution over all independent sets of ${\displaystyle G}$.

We still don't know how long we have to run the chain. This is determine be its mixing time. We will discuss how to analyze the mixing time for general random walks.

## Conductance

### Spectral gap and the mixing time

• We consider a Markov chain with finite space ${\displaystyle {\mathcal {S}}}$, transition matrix ${\displaystyle P}$, and stationary distribution ${\displaystyle \pi }$. Let ${\displaystyle N=|{\mathcal {S}}|}$ denote the size of the state space, and let ${\displaystyle \lambda _{1}\geq \cdots \geq \lambda _{N}}$ be the eigenvalues of ${\displaystyle P}$. For any stochastic matrix ${\displaystyle P}$, it holds that ${\displaystyle 1=\lambda _{1}\geq \cdots \geq \lambda _{N}\geq -1}$.
• The mixing time ${\displaystyle \tau (\epsilon )\,}$ of an irreducible and aperiodic Markov chain is given by the time to be within total variation distance ${\displaystyle \epsilon }$ from ${\displaystyle \pi }$, starting from a worst-case state. Formally,
${\displaystyle \tau _{i}(\epsilon )=\min \left\{t\,\,{\bigg |}\,\,{\frac {1}{2}}\sum _{j\in {\mathcal {S}}}|P^{t}(i,j)-\pi (i)|\leq \epsilon \right\}}$ and ${\displaystyle \tau (\epsilon )=\max _{i\in {\mathcal {S}}}\tau _{i}(\epsilon )}$.

Conditions:

• The Markov chain is time-reversible: ${\displaystyle \pi _{i}P_{i,j}=\pi _{j}P_{j,i}}$ for all ${\displaystyle i,j\in {\mathcal {S}}}$.
For a time-reversible Markov chain, the transition matrix ${\displaystyle P}$ can be transformed to a symmetric matrix, thus the orthogonal diagonalization for symmetric matrices can be applied, and the convergence rate is determined by the second largest absolute value of eigenvalues ${\displaystyle \lambda _{\max }=\max(|\lambda _{2}|,|\lambda _{N}|)}$ as
${\displaystyle \tau _{i}(\epsilon )=O\left({\frac {\ln(1/\pi _{i})+\ln(1/\epsilon )}{1-\lambda _{\max }}}\right)}$.
• Lazy random walk: ${\displaystyle P_{i,i}\geq {\frac {1}{2}}}$ for any ${\displaystyle i\in {\mathcal {S}}}$.
A lazy walk is aperiodic. The eigenvalues of a lazy walk are nonnegative, and thus ${\displaystyle \lambda _{\max }=\max(|\lambda _{2}|,|\lambda _{N}|)=\lambda _{2}}$. The mixing time is determined by the second largest eigenvalue ${\displaystyle \lambda _{2}}$ as
${\displaystyle \tau _{i}(\epsilon )=O\left({\frac {\ln(1/\pi _{i})+\ln(1/\epsilon )}{1-\lambda _{2}}}\right)}$.
• The stationary ${\displaystyle \pi }$ is the uniform distribution, that is, ${\displaystyle \pi _{i}={\frac {1}{N}}}$ for all ${\displaystyle i\in {\mathcal {S}}}$.

Then:

 Theorem The mixing time of a time-reversible lazy random walk with uniform stationary distribution over a state space of size ${\displaystyle N}$, is ${\displaystyle \tau (\epsilon )=O\left({\frac {\ln N+\ln(1/\epsilon )}{1-\lambda _{2}}}\right)}$.

From the previous section, we see how to construct a time-reversible lazy random walk with uniform stationary distribution. The mixing time is now determined by the spectral gap ${\displaystyle (1-\lambda _{2})}$. In order to upper bound the mixing time, we need to lower bound the spectral gap. However, it is difficult to directly bound the eigenvalues of a usually exponentially large transition matrix.

### Conductance and the mixing time

For many problems, such as card shuffling, the state space is exponentially large, so the estimation of ${\displaystyle \lambda _{2}}$ becomes very difficult. The following technique based on conductance overcomes this issue by considering the conductance of a Markov chain.

 Definition (conductance) The conductance of a irreducible Markov chain with finite state space ${\displaystyle \Omega }$, transition matrix ${\displaystyle P}$, and stationary distribution ${\displaystyle \pi }$, is defined as ${\displaystyle \Phi =\min _{\overset {S\subset \Omega }{0<\pi (S)\leq {\frac {1}{2}}}}{\frac {\sum _{i\in S,j\not \in S}\pi _{i}P_{ij}}{\pi (S)}}}$ where ${\displaystyle \pi (S)=\sum _{i\in S}\pi _{i}}$ is the probability density of ${\displaystyle S\subset \Omega }$ under the stationary distribution ${\displaystyle \pi }$.

The definition of conductance looks quite similar to the expansion ratio of graphs. Very informally, the conductance can be seen as the weighted normalized version of expansion ratio.

The following lemma states a Cheeger's inequality for the conductance.

 Lemma (Jerrum-Sinclair 1988) In a time-reversible Markov chain, ${\displaystyle 1-2\Phi \leq \lambda _{2}\leq 1-{\frac {\Phi ^{2}}{2}}}$.

The inequality can be equivalent written for the spectral gap:

${\displaystyle {\frac {\Phi ^{2}}{2}}\leq 1-\lambda _{2}\leq 2\Phi }$.

Thus ${\displaystyle \Phi ^{2}/2}$ is a lower bound of the spectral gap, which in turn gives an upper bound of the mixing time via conductance.

 Proposition The mixing time of a time-reversible lazy random walk with uniform stationary distribution over a state space of size ${\displaystyle N}$, is ${\displaystyle \tau (\epsilon )=O\left({\frac {\ln N+\ln(1/\epsilon )}{\Phi ^{2}}}\right)}$.

So analyzing of mixing time is reduced to analyzing of the second largest eigenvalue, which is reduced to analyzing of the conductance. For some simple Markv chain, this can be done directly. For some more complicated Markov chain, this is done by a technique called the canonical paths argument.

### Canonical paths

We will first show how to lower bound the expansion ratio of a graph by canonical paths argument, and then we will generalize this technique to the conductance.

As we know, the expansion ratio of an undirected graph ${\displaystyle G(V,E)}$,

${\displaystyle \phi (G)=\min _{\overset {S\subset V}{|S|\leq {\frac {|V|}{2}}}}{\frac {|\partial |}{|S|}}}$,

is hard to compute, because its definition involves an optimization over exponentially many subsets. We will see that it can be lower bounded by computing the maximum congestion caused by a set of paths.

For every pair of vertices ${\displaystyle x,y\in V}$, we construct a simple path ${\displaystyle \gamma _{xy}}$ from ${\displaystyle x}$ to ${\displaystyle v}$. Each ordered pair ${\displaystyle (x,y)}$ of distinct vertices corresponds to exact one path, called the canonical path from ${\displaystyle x}$ to ${\displaystyle y}$. Let ${\displaystyle \Gamma =\{\gamma _{xy}\mid x,y\in V,x\neq y\}}$ be the collection of canonical paths.

The set of canonical paths that an edge ${\displaystyle uv}$ is on is

${\displaystyle \mathrm {CP} (uv)=\{\gamma _{xy}\in \Gamma \mid uv\in \gamma _{xy}\}}$.

The congestion of an edge is given by ${\displaystyle |\mathrm {CP} (uv)|}$, which is the number of canonical paths crossing the edge ${\displaystyle uv}$.

For any ${\displaystyle S\subset V}$ where ${\displaystyle |S|\leq {\frac {|V|}{2}}}$, there are ${\displaystyle |S||{\bar {S}}|}$ ordered pairs ${\displaystyle (x,y)}$ of vertices such that ${\displaystyle x\in S}$ and ${\displaystyle y\not \in S}$, thus there are ${\displaystyle |S||{\bar {S}}|}$ canonical paths going from ${\displaystyle S}$ to ${\displaystyle {\bar {S}}}$. The average congestion of edges crossing from ${\displaystyle S}$ and ${\displaystyle {\bar {S}}}$ is ${\displaystyle {\frac {|S||{\bar {S}}|}{|\partial S|}}}$, which must be no bigger than the maximum congestion. Thus,

${\displaystyle \sigma {\overset {\mathrm {def} }{=}}\max _{uv\in E}|\mathrm {CP} (uv)|\geq {\frac {|S||{\bar {S}}|}{|\partial S|}}}$

and

${\displaystyle {\frac {|\partial S|}{|S|}}\geq {\frac {|{\bar {S}}|}{\sigma }}\geq {\frac {|V|}{2\sigma }}}$.

This inequality holds for any ${\displaystyle S\subset V}$ where ${\displaystyle |S|\leq {\frac {|V|}{2}}}$, by the definition of expansion ratio,

${\displaystyle \phi (G)\geq {\frac {|V|}{2\sigma }}}$

Therefore, for any collection of canonical paths ${\displaystyle \Gamma =\{\gamma _{xy}\}}$, the maximum congestion ${\displaystyle \sigma =\max _{uv\in E}|\mathrm {CP} (uv)|}$ caused by ${\displaystyle \Gamma }$ can be used to lower bound ${\displaystyle \phi (G)}$. By choosing cleverer paths, we can make the bound tighter.

The intuition behind this inequality is that large expansion ratio (the graph is well-connected) is a necessary condition for the existence of a pairwise routing scheme with low-congestion.

We now show how to apply the canonical paths argument to the Markov chain and lower bound the conductance of the chain.

For a Markov chain with finite state space ${\displaystyle {\mathcal {S}}}$, and transition matrix ${\displaystyle P}$. The chain corresponds to a transition graph ${\displaystyle {\mathcal {G}}({\mathcal {S}},E)}$ on the state space ${\displaystyle {\mathcal {S}}}$. For any states ${\displaystyle u,v\in {\mathcal {S}}}$, ${\displaystyle uv\in E}$ if ${\displaystyle P_{uv}>0}$.

The canonical paths for the chain is a collection of simple paths ${\displaystyle \Gamma =\{\gamma _{xy}\mid x,y\in {\mathcal {S}},x\neq y\}}$ in the transition graph ${\displaystyle {\mathcal {G}}}$, such that for any ordered pair ${\displaystyle (x,y)}$ of distinct states, there is exact one path ${\displaystyle \gamma _{xy}}$ going from ${\displaystyle x}$ to ${\displaystyle y}$ in ${\displaystyle {\mathcal {G}}}$.

Let ${\displaystyle \Gamma =\{\gamma _{xy}\}}$ be a collection of canonical paths. The congestion caused by ${\displaystyle \Gamma }$ is computed as

${\displaystyle \rho =\max _{uv\in E}{\frac {1}{\pi _{u}P_{uv}}}\sum _{\gamma _{xy}\ni uv}\pi _{x}\pi _{y}}$.

Note that compared to the example of lower bounding the expansion ratio, in which we directly count the number of paths crossing an edge as the congestion, this time the congestion is defined by the probability "flows". This is analogous to the difference between the definitions of expansion ratio of a graph and the conductance of a Markov chain.

 Lemma Let ${\displaystyle \Gamma =\{\gamma _{xy}\}}$ be a collection of canonical path. The conductance is lower bounded by ${\displaystyle \Phi \geq {\frac {1}{2\rho }}}$.
Proof.
${\displaystyle \square }$

Due to the upper bound of the mixing time via the conductance, we have the following proposition.

 Proposition Consider a time-reversible lazy random walk with uniform stationary distribution over a state space of size ${\displaystyle N}$. Let ${\displaystyle \Gamma =\{\gamma _{xy}\}}$ be an arbitrary collection of canonical paths. Assuming that the congestion of ${\displaystyle \Gamma }$ is ${\displaystyle \rho \,}$, the mixing time of the chain is bounded by ${\displaystyle \tau (\epsilon )=O\left(\rho ^{2}\left(\ln N+\ln(1/\epsilon )\right)\right)}$.

### Example: random walk on a cube

We then apply the canonical path argument on a simple Markov chain: the random walk on high dimensional cube.

Let the state space be ${\displaystyle {\mathcal {S}}=[d]^{n}}$. Consider the random walk:

• Start from an arbitrary ${\displaystyle x\in {\mathcal {S}}}$
• At each step, assuming the current state is ${\displaystyle x\in {\mathcal {S}}}$, choose an random ${\displaystyle i\in \{1,2,\ldots ,n\}}$ and a random ${\displaystyle b\in \{-1,1\}}$ and move to the state ${\displaystyle y\in {\mathcal {S}}}$ such that ${\displaystyle y_{i}=(x_{i}+b){\bmod {d}}}$ and ${\displaystyle y_{j}=x_{j}}$ for ${\displaystyle j\neq i}$.

The Markov chain is a random walk on an ${\displaystyle n}$-dimensional ${\displaystyle d}$-ary cube ${\displaystyle G(V,E)}$, where ${\displaystyle V=[d]^{n}}$, and ${\displaystyle uv\in E}$ if ${\displaystyle u}$ and ${\displaystyle v}$ differ in one coordinate by 1 (modular ${\displaystyle d}$). And for any ${\displaystyle uv\in E}$, the transition probability ${\displaystyle P_{uv}={\frac {1}{2n}}}$.

We will show that the walk is rapid mixing by the canonical paths argument. The argument involves the following steps:

• Construct a collection of canonical paths.
• Bound the congestion of a single edge. This step is usually done by "encoding" the canonical paths crossing the edge.
• Compute the ${\displaystyle \rho \,}$ and thus bound the mixing time.
Construct the canonical paths

Consider the canonical paths ${\displaystyle \Gamma =\{\gamma _{xy}\}}$ defined by the following "fixing" scheme:

• For each ${\displaystyle x,y\in {\mathcal {S}}}$, ${\displaystyle \gamma _{xy}}$ is the path obtained by fixing the 1st, 2nd, ... ${\displaystyle n}$th coordinate of ${\displaystyle x}$, by increasing each coordinate by one (modula ${\displaystyle d}$) at a time. The path is described by the following pseudocode.
for(i=1; i<=d; i++){
while(x[i]!=y[i]){
x[i]=(x[i]+1)mod d;
}
}

Bound the congestion ${\displaystyle |\mathrm {CP} (uv)|}$

For any edge ${\displaystyle uv\in E}$, i.e. such ${\displaystyle u,v\in [d]^{n}}$ that differ at one coordinate by 1, let

${\displaystyle \mathrm {CP} (uv)=\{\gamma _{xy}\in \Gamma \mid uv\in \gamma _{xy}\}}$

be the set of canonical paths crossing the edge ${\displaystyle uv}$. The value ${\displaystyle |\mathrm {CP} (uv)|}$ is the number of canonical paths crossing ${\displaystyle uv}$.

We claim that for any ${\displaystyle uv\in E}$

${\displaystyle |\mathrm {CP} (uv)|\leq d^{n+1}}$.

To see this, consider an edge from ${\displaystyle u=(u_{1},u_{2},\ldots ,u_{n})\,}$ to ${\displaystyle v=(u_{1},u_{2},\ldots ,u_{i-1},(u_{i}+1){\bmod {d}},u_{i+1},\ldots ,u_{n})\,}$. The idea of the argument is that the ${\displaystyle \gamma _{xy}}$ that cross the edge ${\displaystyle uv}$ must satisfy:

• ${\displaystyle y_{1}=u_{1},\ldots ,y_{i-1}=u_{i-1}\,}$ and
• ${\displaystyle x_{i+1}=u_{i+1},\ldots ,x_{n}=u_{n}\,}$,

because we are modifying the coordinates in order ${\displaystyle 1,2,\ldots ,n}$. More precisely, corresponding to any ${\displaystyle \gamma _{xy}}$ that cross the edge ${\displaystyle uv}$, we may define a complementary point ${\displaystyle w\in [d]^{n}}$ as

${\displaystyle w=(x_{1},x_{2},\ldots ,x_{i},y_{i+1},y_{i+2},\ldots ,y_{n})\,}$.

Then, for any fixed edge ${\displaystyle uv}$, given ${\displaystyle w}$ and ${\displaystyle y_{i}}$, a pair of ${\displaystyle x}$ and ${\displaystyle y}$ whose canonical path cross the ${\displaystyle uv}$, can be uniquely determined. In other words, a canonical path ${\displaystyle \gamma _{xy}\in \mathrm {CP} (uv)}$ can be encoded as a pair of ${\displaystyle w\in [d]^{n}}$ and ${\displaystyle y_{i}\in [d]}$. Thus,

${\displaystyle |\mathrm {CP} (uv)|\leq |[d]^{n}\times [d]|=d^{n+1}}$.

Compute the ${\displaystyle \rho \,}$ from ${\displaystyle |\mathrm {CP} (uv)|}$

Since the cube is a regular graph, the stationary distribution is uniform, so ${\displaystyle \pi _{x}=d^{-n}}$ for any ${\displaystyle x\in [d]^{n}}$. Recall that ${\displaystyle P_{uv}={\frac {1}{2n}}}$ for any ${\displaystyle uv\in E}$. The ${\displaystyle \rho \,}$ can be computed by

${\displaystyle \rho =\max _{uv\in E}{\frac {1}{\pi _{u}P_{uv}}}\sum _{\gamma _{xy}\ni uv}\pi _{x}\pi _{y}=\max _{uv\in E}{\frac {|\mathrm {CP} (uv)|}{d^{n}\cdot P_{uv}}}\leq 2nd}$.

Therefore, the mixing time is bounded by ${\displaystyle O(n^{2}d^{2}\cdot \log(d^{n}))=O(n^{3}d^{2}\log d)}$, which is logarithmic to the size of the state space ${\displaystyle |{\mathcal {S}}|=d^{n}}$.

Generalizing the technique:

• For a Markov chain with ${\displaystyle N}$ states, the chain can be represented as a transition graph ${\displaystyle {\mathcal {G}}({\mathcal {S}},E)}$ on the state space. Let ${\displaystyle d}$ be the maximum degree of ${\displaystyle {\mathcal {G}}}$.
• If the stationary is uniform, the ${\displaystyle \rho \,}$ becomes
${\displaystyle \rho =\max _{uv\in E}{\frac {1}{\pi _{u}P_{uv}}}\sum _{\gamma _{xy}\ni uv}\pi _{x}\pi _{y}=\max _{uv\in E}{\frac {|\mathrm {CP} (uv)|}{N\cdot P_{uv}}}}$.
• For Metropolis algorithms which generate uniform stationary distribution, ${\displaystyle P_{uv}}$ are equal for all ${\displaystyle uv\in E}$ and ${\displaystyle 1/P_{uv}}$ can be made ${\displaystyle \leq 2d}$ for a lazy random walk.
• Therefore, the Markov chain is rapid mixing if the maximum degree ${\displaystyle d}$ of the transition graph is within polynomial of ${\displaystyle \log N}$, and ${\displaystyle {\frac {|\mathrm {CP} (uv)|}{N}}}$ is within polynomial of ${\displaystyle \log N}$ for any edge ${\displaystyle uv\in E}$. Usually, the maximum degree of ${\displaystyle {\mathcal {G}}}$ can be made small, thus the only problem is to bound the maximum ${\displaystyle {\frac {|\mathrm {CP} (uv)|}{N}}}$ within polynomial of ${\displaystyle \log N}$.
• The ${\displaystyle |\mathrm {CP} (uv)|\,}$ for any ${\displaystyle uv}$ can be bound by encoding the pair ${\displaystyle (x,y)}$ that ${\displaystyle \gamma _{xy}\in \mathrm {CP} (uv)}$ by a complementary state ${\displaystyle w\in {\mathcal {S}}}$ plus some parameter. There are ${\displaystyle N}$ states, and assuming the parameter ranging over ${\displaystyle M}$ different values, the ${\displaystyle {\frac {|\mathrm {CP} (uv)|}{N}}}$ is bounded by ${\displaystyle M}$. If ${\displaystyle M}$ is poly-log of ${\displaystyle N}$, then the Markov chain is rapid mixing.

## Sampling Perfect Matchings

Matchings are edge independent sets for graphs. Formally, for any graph ${\displaystyle G(V,E)}$, an edge subset ${\displaystyle M\subset E}$ is a matching if any distinct pair of ${\displaystyle e,e'\in M}$ do not share an endpoint. A matching ${\displaystyle M}$ is said to be perfect if ${\displaystyle |M|=|V|}$ since it matches all the vertices.

Consider the problem of uniformly sampling a perfect matching for a dense bipartite graph.

### The Markov chain

We fix a bipartite graph ${\displaystyle G(V_{1},V_{2},E)}$ with ${\displaystyle |V_{1}|=|V_{2}|=n}$, and minimum degree at least ${\displaystyle n/2}$. Let ${\displaystyle {\mathcal {M}}_{k}}$ denote the set of distinct matchings of size ${\displaystyle k}$ in ${\displaystyle G}$. Thus, ${\displaystyle {\mathcal {M}}_{n}}$ is the set of the perfect matchings of the dense bipartite graph ${\displaystyle G}$. Our goal is to uniformly sample an ${\displaystyle M\in {\mathcal {M}}_{n}}$.

We extend the space to the ${\displaystyle {\mathcal {M}}_{n}\cup {\mathcal {M}}_{n-1}}$, can consider the following types of transitions closed within the space:

• Reduce: For an ${\displaystyle M\in {\mathcal {M}}_{n}}$ and an edge ${\displaystyle uv\in M}$, ${\displaystyle \mathrm {reduce} (M,uv)=M-uv}$.
• Augment: For an ${\displaystyle M\in {\mathcal {M}}_{n-1}}$ and an edge ${\displaystyle uv\in E}$ with ${\displaystyle u}$ and ${\displaystyle v}$ unmatched in ${\displaystyle M}$, ${\displaystyle \mathrm {augment} (M,uv)=M+uv}$.
• Rotate: For an ${\displaystyle M\in {\mathcal {M}}_{n-1}}$ and an edge ${\displaystyle uv\in E}$ with ${\displaystyle uw\in M}$ and ${\displaystyle v}$ unmatched in ${\displaystyle M}$, ${\displaystyle \mathrm {rotate} (M,uv)=M-uw+uv}$.

${\displaystyle \mathrm {reduce} }$ transforms from ${\displaystyle {\mathcal {M}}_{n}}$ to ${\displaystyle {\mathcal {M}}_{n-1}}$; ${\displaystyle \mathrm {augment} }$ transforms from ${\displaystyle {\mathcal {M}}_{n-1}}$ to ${\displaystyle {\mathcal {M}}_{n}}$; and ${\displaystyle \mathrm {rotate} }$ stays in ${\displaystyle {\mathcal {M}}_{n-1}}$.

It is easy to see that for any ${\displaystyle M}$ and any ${\displaystyle uv}$, at most one of the ${\displaystyle \mathrm {reduce} (M,uv)}$, ${\displaystyle \mathrm {augment} (M,uv)}$, and ${\displaystyle \mathrm {rotate} (M,uv)}$ can be applied.

A Markov chain with state space ${\displaystyle {\mathcal {M}}_{n}\cup {\mathcal {M}}_{n-1}}$ is defined as follows:

• Suppose that the current matching is ${\displaystyle M}$. With probability ${\displaystyle 1/2}$, stay at the current state; otherwise:
• Uniformly choose a random edge ${\displaystyle uv\in E}$, and if any one of the ${\displaystyle \mathrm {reduce} (M,uv)}$, ${\displaystyle \mathrm {augment} (M,uv)}$, and ${\displaystyle \mathrm {rotate} (M,uv)}$ is applicable, apply the transformation; otherwise stay at the current state.

We claim that this Markov chain is irreducible, aperiodic, and time-reversible, and the stationary distribution ${\displaystyle \pi }$ is the uniform distribution over ${\displaystyle {\mathcal {M}}_{n}\cup {\mathcal {M}}_{n-1}}$.

• Irreducibility: Any ${\displaystyle M\in {\mathcal {M}}_{n}\cup {\mathcal {M}}_{n-1}}$ can be transformed to any ${\displaystyle M'\in {\mathcal {M}}_{n}\cup {\mathcal {M}}_{n-1}}$ by a suitable sequence of augmentations, reductions, and rotations.
• Aperiodic: The loop probabilities are non zero.
• Time-reversible and uniform stationary distribution: Each transition of the Markov chain has the same associated probability of ${\displaystyle {\frac {1}{2|E|}}}$.

So the Markov chain will eventually return a near-uniform matching in ${\displaystyle {\mathcal {M}}_{n}\cup {\mathcal {M}}_{n-1}}$. We can use the rejection sampling to sample a perfect matching ${\displaystyle M\in {\mathcal {M}}_{n}}$ by repeatedly sampling until the sampled ${\displaystyle M}$ is in ${\displaystyle {\mathcal {M}}_{n}}$. The efficiency of this algorithm relies on two quantities: the ratio of ${\displaystyle {\frac {|{\mathcal {M}}_{n-1}|}{|{\mathcal {M}}_{n}|}}}$, and the mixing time of the Markov chain.

The following theorem holds for the ratio between the number of near-perfect matchings and the number of perfect matchings in a dense bipartite graph.

 Theorem (Broder 1986) For any bipartite graph ${\displaystyle G(V_{1},V_{2},E)}$ with ${\displaystyle |V_{1}|=|V_{2}|=n}$, and minimum degree at least ${\displaystyle n/2}$, ${\displaystyle {\frac {|{\mathcal {M}}_{n-1}|}{|{\mathcal {M}}_{n}|}}=O(n^{2})}$.

So the only remaining issue is to bound the mixing time of the Markov chain. We use the canonical paths.

### Canonical paths

For any matching ${\displaystyle M\in {\mathcal {M}}_{n}\cup {\mathcal {M}}_{n-1}}$, let ${\displaystyle {\overline {M}}\in {\mathcal {M}}_{n}}$ be a unique matching in ${\displaystyle {\mathcal {M}}_{n}}$, called the partner of ${\displaystyle M}$.

• For ${\displaystyle M\in {\mathcal {M}}_{n}}$, we define ${\displaystyle {\overline {M}}=M}$.
• For ${\displaystyle M\in {\mathcal {M}}_{n-1}}$, there are only two possible cases
1. If there exists an ${\displaystyle uv\in E}$ with both ${\displaystyle u}$ and ${\displaystyle v}$ unmatched in ${\displaystyle M}$, then ${\displaystyle {\overline {M}}=\mathrm {augment} (M,uv)=M+uv}$.
2. If otherwise, then there exists at least one matching in ${\displaystyle {\mathcal {M}}_{n}}$ that can be transformed from ${\displaystyle M}$ by a rotation and then an augmentation. Choose one of such matchings in ${\displaystyle {\mathcal {M}}_{n}}$ as the unique ${\displaystyle {\overline {M}}}$.

The canonical path from an ${\displaystyle S\in {\mathcal {M}}_{n}\cup {\mathcal {M}}_{n-1}}$ to a ${\displaystyle T\in {\mathcal {M}}_{n}\cup {\mathcal {M}}_{n-1}}$ is defined by three parts:

1. From ${\displaystyle S}$ to its partner ${\displaystyle {\overline {S}}\in {\mathcal {M}}_{n}}$; (Type A)
2. then from ${\displaystyle {\overline {S}}\in {\mathcal {M}}_{n}}$ to the ${\displaystyle T}$'s partner ${\displaystyle {\overline {T}}\in {\mathcal {M}}_{n}}$; (Type B)
3. and at last from ${\displaystyle {\overline {T}}}$ to ${\displaystyle T}$. (Type A)

The first and the third parts are between a matching and its partner in ${\displaystyle {\mathcal {M}}_{n}}$, called the type A path, and the second part is between two matchings in ${\displaystyle {\mathcal {M}}_{n}}$, called the type B path.

For the rest, see textbook Chap 11.3.