TExcelTAD
Home › Spectral Graph Theory & Modern Graph Algorithms › Mixing of Random Walks via the Spectral Gap

Mixing of Random Walks via the Spectral Gap

A random walk on a connected non-bipartite graph converges to its stationary distribution π(v)=dv/2m\pi(v) = d_v/2m. How fast is the question behind every sampling algorithm and every "random walk explores the graph" argument. Stationary Distributions and Mixing Time measured mixing times by computation and coupling; here we prove the spectral bound: the distance to π\pi shrinks by a factor 1−ν2/21 - \nu_2/2 per step of the lazy walk. Combined with Cheeger's inequality, this says a walk mixes fast exactly when the graph has no sparse cut.

The lazy walk in spectral form

Let GG be connected and use column vectors for distributions, pt+1=Mptp_{t+1} = Mp_t with the lazy walk matrix

M=12(I+AD−1)=D1/2(I−12N)D−1/2,M = \tfrac12\big(I + AD^{-1}\big) = D^{1/2}\Big(I - \tfrac12 N\Big)D^{-1/2},

where N=I−D−1/2AD−1/2N = I - D^{-1/2}AD^{-1/2} is the normalized Laplacian. So MM is similar to the symmetric matrix I−12NI - \frac12 N, whose eigenvalues are ωi=1−νi2∈[0,1]\omega_i = 1 - \frac{\nu_i}{2} \in [0, 1], with ω1=1\omega_1 = 1 for the eigenvector y1=D1/21/2my_1 = D^{1/2}\mathbf{1}/\sqrt{2m}. Laziness makes every ωi\omega_i nonnegative, which removes the oscillation of bipartite graphs (νn=2\nu_n = 2 becomes ωn=0\omega_n = 0).

Theorem. For the lazy walk started at vertex aa, after tt steps, for every vertex bb,

∣pt(b)−π(b)∣≤dbda (1−ν22)t.\lvert p_t(b) - \pi(b) \rvert \le \sqrt{\frac{d_b}{d_a}}\ \Big(1 - \frac{\nu_2}{2}\Big)^{t} .

Proof. Let y1,…,yny_1, \ldots, y_n be an orthonormal eigenbasis of NN and write D−1/2ea=∑iciyiD^{-1/2}\mathbf{e}_a = \sum_i c_i y_i. Then pt=Mtea=D1/2(I−12N)tD−1/2ea=∑iωitciD1/2yip_t = M^t \mathbf{e}_a = D^{1/2}(I - \frac12 N)^t D^{-1/2}\mathbf{e}_a = \sum_i \omega_i^t c_i D^{1/2} y_i. The i=1i = 1 term is c1D1/2y1c_1 D^{1/2}y_1 with c1=y1TD−1/2ea=12mc_1 = y_1^{\mathsf{T}} D^{-1/2}\mathbf{e}_a = \frac{1}{\sqrt{2m}}, so it equals D12m=π\frac{D\mathbf{1}}{2m} = \pi. For the rest,

∣pt(b)−π(b)∣=∣db∑i≥2ωitci yi(b)∣≤db ω2t(∑ici2)1/2(∑iyi(b)2)1/2=db ω2t 1da,\lvert p_t(b) - \pi(b) \rvert = \Big\lvert \sqrt{d_b} \sum_{i \ge 2} \omega_i^t c_i\, y_i(b) \Big\rvert \le \sqrt{d_b}\ \omega_2^t \Big(\sum_i c_i^2\Big)^{1/2} \Big(\sum_i y_i(b)^2\Big)^{1/2} = \sqrt{d_b}\ \omega_2^t\ \frac{1}{\sqrt{d_a}},

by Cauchy-Schwarz, ∑ici2=∥D−1/2ea∥2=1/da\sum_i c_i^2 = \lVert D^{-1/2}\mathbf{e}_a \rVert^2 = 1/d_a, and ∑iyi(b)2=1\sum_i y_i(b)^2 = 1 (the rows of an orthogonal matrix are unit vectors). □\square

Summing over bb, the total-variation distance satisfies ∥pt−π∥TV≤n2dmax⁡dmin⁡ ω2t≤n2dmax⁡dmin⁡ e−tν2/2\lVert p_t - \pi \rVert_{TV} \le \frac{n}{2}\sqrt{\frac{d_{\max}}{d_{\min}}}\, \omega_2^t \le \frac{n}{2}\sqrt{\frac{d_{\max}}{d_{\min}}}\, e^{-t\nu_2/2}, so

tmix(ε)≤2ν2ln⁡ ⁣(n2εdmax⁡dmin⁡).t_{\text{mix}}(\varepsilon) \le \frac{2}{\nu_2} \ln\!\Big(\frac{n}{2\varepsilon}\sqrt{\frac{d_{\max}}{d_{\min}}}\Big) .

The relaxation time 1/(1−ω2)=2/ν21/(1 - \omega_2) = 2/\nu_2 sets the scale, up to a logarithmic factor; and the scale is right, since tmix(ε)≥(2ν2−1)ln⁡12εt_{\text{mix}}(\varepsilon) \ge (\frac{2}{\nu_2} - 1)\ln\frac{1}{2\varepsilon} for reversible chains (Levin, Peres and Wilmer, Theorem 12.5). With Cheeger's inequality ν2≥ϕ2/2\nu_2 \ge \phi^2/2, a graph of conductance ϕ\phi mixes in O(ϕ−2log⁡n)O(\phi^{-2}\log n) steps (for bounded degree ratio), and a sparse cut forces slow mixing.

Watching it happen

The lab runs the lazy walk from node 0 on three 12-node graphs: a cycle, a barbell (two 6-cliques joined by one edge) and a 4-regular circulant (jumps of 1 and 5). It shows the exact distribution after tt steps and the total-variation distance to π\pi; the mixing times (first tt with distance at most 14\frac14) are 14, 29 and 4.

01234567891011after 40 steps: circle area ∝ probability (start at node 0)0¼½102040steps tdistance to π

The program computes the same three walks exactly, together with ν2\nu_2, the relaxation time and the spectral upper bound on tmix(14)t_{\text{mix}}(\frac14).

python · try it yourself
import numpy as np

n = 12
graphs = {
    "cycle": [(i, (i + 1) % n) for i in range(n)],
    "barbell": [(a + s, b + s) for s in (0, 6) for a in range(6) for b in range(a + 1, 6)] + [(5, 6)],
    "circulant": [(i, (i + j) % n) for i in range(n) for j in (1, 5)],
}
print("graph       nu_2     2/nu_2   t_mix from node 0   spectral bound on t_mix(1/4)")
for name, edges in graphs.items():
    A = np.zeros((n, n))
    for u, v in edges:
        A[u, v] = A[v, u] = 1
    d = A.sum(axis=1)
    s = 1 / np.sqrt(d)
    nu2 = float(np.linalg.eigvalsh(np.eye(n) - s[:, None] * A * s[None, :])[1])
    M = (np.eye(n) + A / d[None, :]) / 2           # column-stochastic lazy walk
    pi = d / d.sum()
    p = np.zeros(n); p[0] = 1.0
    t = 0
    while 0.5 * np.abs(p - pi).sum() > 0.25:
        p = M @ p; t += 1
    bound = 2 / nu2 * np.log(n / (2 * 0.25) * np.sqrt(d.max() / d.min()))
    print(f"{name:10} {nu2:7.4f}  {2 / nu2:7.2f}  {t:17}   {bound:27.1f}")
graph       nu_2     2/nu_2   t_mix from node 0   spectral bound on t_mix(1/4)
cycle       0.1340    14.93                 14                          47.4
barbell     0.0507    39.48                 29                         129.1
circulant   0.5000     4.00                  4                          12.7

The ordering of the three graphs is exactly the ordering of their spectral gaps, and the relaxation time 2/ν22/\nu_2 is within a small factor of the true mixing time. The spectral bound is an over-estimate by the logarithmic factor, which matters little for asymptotics.

The pointwise bound in action

The theorem is a bound for each target vertex. The program follows the walk on the barbell from vertex 0 and compares the worst deviation max⁡b∣pt(b)−π(b)∣da/db\max_b \lvert p_t(b) - \pi(b) \rvert \sqrt{d_a/d_b} with ω2t\omega_2^t.

python · try it yourself
import numpy as np

n = 12
edges = [(a + s, b + s) for s in (0, 6) for a in range(6) for b in range(a + 1, 6)] + [(5, 6)]
A = np.zeros((n, n))
for u, v in edges:
    A[u, v] = A[v, u] = 1
d = A.sum(axis=1)
s = 1 / np.sqrt(d)
nu = np.linalg.eigvalsh(np.eye(n) - s[:, None] * A * s[None, :])
omega2 = 1 - nu[1] / 2
M = (np.eye(n) + A / d[None, :]) / 2
pi = d / d.sum()
p = np.zeros(n); p[0] = 1.0
for t in range(1, 121):
    p = M @ p
    if t in (1, 10, 30, 60, 120):
        dev = float(np.max(np.abs(p - pi) * np.sqrt(d[0] / d)))
        print(f"t = {t:3}: max_b |p_t(b) - pi(b)| sqrt(d_a/d_b) = {dev:.3e}   omega_2^t = {float(omega2 ** t):.3e}")
t =   1: max_b |p_t(b) - pi(b)| sqrt(d_a/d_b) = 4.194e-01   omega_2^t = 9.747e-01
t =  10: max_b |p_t(b) - pi(b)| sqrt(d_a/d_b) = 6.834e-02   omega_2^t = 7.737e-01
t =  30: max_b |p_t(b) - pi(b)| sqrt(d_a/d_b) = 4.085e-02   omega_2^t = 4.632e-01
t =  60: max_b |p_t(b) - pi(b)| sqrt(d_a/d_b) = 1.892e-02   omega_2^t = 2.145e-01
t = 120: max_b |p_t(b) - pi(b)| sqrt(d_a/d_b) = 4.059e-03   omega_2^t = 4.602e-02

The deviation stays below ω2t\omega_2^t throughout, and after the first few steps it decays at exactly the rate ω2\omega_2 (from t=60t = 60 to t=120t = 120 it shrinks by ω260≈0.21\omega_2^{60} \approx 0.21): the walk's distance to π\pi is dominated by the second eigenvector, which is positive on one clique and negative on the other, i.e. by the imbalance of probability between the two halves that the bridge slowly repairs.

In C++

The spectral bound becomes useful when the graph is too large to diagonalize. On the hypercube Q10Q_{10} (1024 vertices, ν2=2/d=0.2\nu_2 = 2/d = 0.2, ω2=0.9\omega_2 = 0.9), the C++ program evolves the exact distribution and reports the first tt with total-variation distance at most 14\frac14, against the spectral bound 2ν2ln⁡(2n)\frac{2}{\nu_2}\ln(2n).

cpp · try it yourself
#include <cmath>
#include <cstdio>
#include <vector>

int main() {
    const int d = 10, n = 1 << d;
    std::vector<double> p(n, 0.0), q(n);
    p[0] = 1.0;
    const double pi = 1.0 / n;                   // regular graph: uniform stationary distribution
    for (int t = 1; t <= 200; ++t) {
        for (int v = 0; v < n; ++v) {
            double s = 0;
            for (int i = 0; i < d; ++i) s += p[v ^ (1 << i)];
            q[v] = 0.5 * p[v] + 0.5 * s / d;     // lazy step
        }
        p.swap(q);
        double tv = 0;
        for (double x : p) tv += std::fabs(x - pi);
        tv /= 2;
        if (t % 5 == 0 || tv <= 0.25) std::printf("t = %3d: TV distance %.4f\n", t, tv);
        if (tv <= 0.25) {
            double nu2 = 2.0 / d;
            std::printf("t_mix(1/4) = %d; spectral bound (2/nu_2) ln(2n) = %.1f\n", t, 2.0 / nu2 * std::log(2.0 * n));
            break;
        }
    }
}
t =   5: TV distance 0.7399
t =  10: TV distance 0.4429
t =  15: TV distance 0.2667
t =  16: TV distance 0.2395
t_mix(1/4) = 16; spectral bound (2/nu_2) ln(2n) = 76.2

The true mixing time, 16 steps, is of order d2ln⁡d≈11.5\frac{d}{2}\ln d \approx 11.5 (plus a term of order dd) and about a fifth of the bound: the spectral argument charges ln⁡n=dln⁡2\ln n = d\ln 2 where coupling shows ln⁡d\ln d suffices, an instance of the "cutoff phenomenon" that the ℓ2\ell_2 argument cannot see.

Test yourself

What are the eigenvalues of the lazy walk matrix 12(I+AD−1)\frac12(I + AD^{-1}) in terms of the normalized Laplacian eigenvalues νi\nu_i?

  1. νi/2\nu_i/2
  2. 1−νi/21 - \nu_i/2
  3. 1−νi1 - \nu_i
  4. (1−νi)2(1 - \nu_i)^2

Which bound did the lesson prove for the lazy walk started at aa?

  1. ∣pt(b)−π(b)∣≤(1−ν2)t\lvert p_t(b) - \pi(b) \rvert \le (1 - \nu_2)^t
  2. ∣pt(b)−π(b)∣≤db/da (1−ν2/2)t\lvert p_t(b) - \pi(b) \rvert \le \sqrt{d_b/d_a}\,(1 - \nu_2/2)^t
  3. ∣pt(b)−π(b)∣≤e−t\lvert p_t(b) - \pi(b) \rvert \le e^{-t}
  4. ∣pt(b)−π(b)∣≤ν2t\lvert p_t(b) - \pi(b) \rvert \le \nu_2^t

Why is the barbell's mixing time so much larger than the circulant's, although both have 12 vertices?

  1. The barbell has more edges
  2. Its single bridge gives tiny conductance, hence a tiny ν2\nu_2 (Cheeger) and a large relaxation time 2/ν22/\nu_2
  3. The barbell is bipartite
  4. The circulant is not regular

How do relaxation time and mixing time compare for reversible chains?

  1. They are unrelated
  2. Mixing time is within a logarithmic factor of the relaxation time 2/ν22/\nu_2, from both sides up to constants
  3. Mixing time is always exactly the relaxation time
  4. Mixing time is the square of the relaxation time