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 on vertices, uniformly sample an independent set of .
By the MCMC method, we consider a Markov chain whose state space is the space of all independent sets of . Our sampling algorithm simply run the Markov chain for a sufficiently long time , and return the current independent set at time .
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 . 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 .
We consider an enormously large transition graph whose vertex set is the state space . That is, every vertex of is an independent set of .
- Irreducibility
- Two independent sets are adjacent to each other in the transition graph , if they differ from each other in just one vertex, formally, if or for some vertex of . It is easy to see that the transition graph is connected, since any independent set is connected to by a series of removals of vertices. The connectivity of the transition graph 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 , the loop probability . 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 , which is not necessarily regular. Let be the maximum degree of .
The Metropolis algorithm - Let . Consider a Markov chain with the transition matrix
- The Markov chain is time-reversible, and the stationary distribution is the uniform distribution.
- Let . Consider a Markov chain with the transition matrix
Proof. Because the graph is undirected, is symmetric. It follows that the uniform distribution is stationary. And , thus the Markov chain is time-reversible.
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 . The transition graph is defined on the space of all independent sets of , and two independent sets are adjacent in if they differ from each other in exact one vertex. This gives us a large undirected graph whose vertices are independent sets of . We consider the following random walk on .
Random walk on Given as the input an undirected graph :
- .
- At step , assuming that the current independent set is , the is computed:
- choose a vertex uniformly at random from ;
- if then ;
- if and , then ;
- otherwise, .
For any independent sets of , if , where is the symmetric difference, then the transition probability is ; if for some , then with probability , is chosen and the transition from to occurs, thus . This corresponds to a random walk over that each undirected edge of has a probability weight of .
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 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 .
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 , transition matrix , and stationary distribution . Let denote the size of the state space, and let be the eigenvalues of . For any stochastic matrix , it holds that .
- The mixing time of an irreducible and aperiodic Markov chain is given by the time to be within total variation distance from , starting from a worst-case state. Formally,
- and .
Conditions:
- The Markov chain is time-reversible: for all .
- For a time-reversible Markov chain, the transition matrix 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 as
- .
- Lazy random walk: for any .
- A lazy walk is aperiodic. The eigenvalues of a lazy walk are nonnegative, and thus . The mixing time is determined by the second largest eigenvalue as
- .
- The stationary is the uniform distribution, that is, for all .
Then:
Theorem - The mixing time of a time-reversible lazy random walk with uniform stationary distribution over a state space of size , is
- .
- The mixing time of a time-reversible lazy random walk with uniform stationary distribution over a state space of size , is
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 . 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 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 , transition matrix , and stationary distribution , is defined as
- where is the probability density of under the stationary distribution .
- The conductance of a irreducible Markov chain with finite state space , transition matrix , and stationary distribution , is defined as
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, .
The inequality can be equivalent written for the spectral gap:
- .
Thus 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 , is
- .
- The mixing time of a time-reversible lazy random walk with uniform stationary distribution over a state space of size , is
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 ,
- ,
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 , we construct a simple path from to . Each ordered pair of distinct vertices corresponds to exact one path, called the canonical path from to . Let be the collection of canonical paths.
The set of canonical paths that an edge is on is
- .
The congestion of an edge is given by , which is the number of canonical paths crossing the edge .
For any where , there are ordered pairs of vertices such that and , thus there are canonical paths going from to . The average congestion of edges crossing from and is , which must be no bigger than the maximum congestion. Thus,
and
- .
This inequality holds for any where , by the definition of expansion ratio,
Therefore, for any collection of canonical paths , the maximum congestion caused by can be used to lower bound . 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 , and transition matrix . The chain corresponds to a transition graph on the state space . For any states , if .
The canonical paths for the chain is a collection of simple paths in the transition graph , such that for any ordered pair of distinct states, there is exact one path going from to in .
Let be a collection of canonical paths. The congestion caused by is computed as
- .
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 be a collection of canonical path. The conductance is lower bounded by
- .
- Let be a collection of canonical path. The conductance is lower bounded by
Proof.
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 . Let be an arbitrary collection of canonical paths. Assuming that the congestion of is , the mixing time of the chain is bounded by
- .
- Consider a time-reversible lazy random walk with uniform stationary distribution over a state space of size . Let be an arbitrary collection of canonical paths. Assuming that the congestion of is , the mixing time of the chain is bounded by
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 . Consider the random walk:
- Start from an arbitrary
- At each step, assuming the current state is , choose an random and a random and move to the state such that and for .
The Markov chain is a random walk on an -dimensional -ary cube , where , and if and differ in one coordinate by 1 (modular ). And for any , the transition probability .
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 and thus bound the mixing time.
- Construct the canonical paths
Consider the canonical paths defined by the following "fixing" scheme:
- For each , is the path obtained by fixing the 1st, 2nd, ... th coordinate of , by increasing each coordinate by one (modula ) 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
For any edge , i.e. such that differ at one coordinate by 1, let
be the set of canonical paths crossing the edge . The value is the number of canonical paths crossing .
We claim that for any
- .
To see this, consider an edge from to . The idea of the argument is that the that cross the edge must satisfy:
- and
- ,
because we are modifying the coordinates in order . More precisely, corresponding to any that cross the edge , we may define a complementary point as
- .
Then, for any fixed edge , given and , a pair of and whose canonical path cross the , can be uniquely determined. In other words, a canonical path can be encoded as a pair of and . Thus,
- .
- Compute the from
Since the cube is a regular graph, the stationary distribution is uniform, so for any . Recall that for any . The can be computed by
- .
Therefore, the mixing time is bounded by , which is logarithmic to the size of the state space .
Generalizing the technique:
- For a Markov chain with states, the chain can be represented as a transition graph on the state space. Let be the maximum degree of .
- If the stationary is uniform, the becomes
- .
- For Metropolis algorithms which generate uniform stationary distribution, are equal for all and can be made for a lazy random walk.
- Therefore, the Markov chain is rapid mixing if the maximum degree of the transition graph is within polynomial of , and is within polynomial of for any edge . Usually, the maximum degree of can be made small, thus the only problem is to bound the maximum within polynomial of .
- The for any can be bound by encoding the pair that by a complementary state plus some parameter. There are states, and assuming the parameter ranging over different values, the is bounded by . If is poly-log of , then the Markov chain is rapid mixing.
Sampling Perfect Matchings
Matchings are edge independent sets for graphs. Formally, for any graph , an edge subset is a matching if any distinct pair of do not share an endpoint. A matching is said to be perfect if 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 with , and minimum degree at least . Let denote the set of distinct matchings of size in . Thus, is the set of the perfect matchings of the dense bipartite graph . Our goal is to uniformly sample an .
We extend the space to the , can consider the following types of transitions closed within the space:
- Reduce: For an and an edge , .
- Augment: For an and an edge with and unmatched in , .
- Rotate: For an and an edge with and unmatched in , .
transforms from to ; transforms from to ; and stays in .
It is easy to see that for any and any , at most one of the , , and can be applied.
A Markov chain with state space is defined as follows:
- Suppose that the current matching is . With probability , stay at the current state; otherwise:
- Uniformly choose a random edge , and if any one of the , , and 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 is the uniform distribution over .
- Irreducibility: Any can be transformed to any 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 .
So the Markov chain will eventually return a near-uniform matching in . We can use the rejection sampling to sample a perfect matching by repeatedly sampling until the sampled is in . The efficiency of this algorithm relies on two quantities: the ratio of , 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 with , and minimum degree at least ,
- .
- For any bipartite graph with , and minimum degree at least ,
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 , let be a unique matching in , called the partner of .
- For , we define .
- For , there are only two possible cases
- If there exists an with both and unmatched in , then .
- If otherwise, then there exists at least one matching in that can be transformed from by a rotation and then an augmentation. Choose one of such matchings in as the unique .
The canonical path from an to a is defined by three parts:
- From to its partner ; (Type A)
- then from to the 's partner ; (Type B)
- and at last from to . (Type A)
The first and the third parts are between a matching and its partner in , called the type A path, and the second part is between two matchings in , called the type B path.
For the rest, see textbook Chap 11.3.