TExcelTAD
Home › Streaming, Sketching & Sublinear Algorithms › Spectral Sparsifiers by Effective Resistances

Spectral Sparsifiers by Effective Resistances

A cut sparsifier preserves w(∂S)w(\partial S) for every vertex set SS. Spielman and Teng (2004) asked for more: preserve the quadratic form of the Laplacian for every real vector, not only for 0/1 indicator vectors. Such a spectral sparsifier preserves cuts, but also eigenvalues, effective resistances, random-walk behaviour and the solutions of Laplacian linear systems, which made it a cornerstone of fast graph algorithms. Spielman and Srivastava (2008) found the simplest construction: sample each edge with probability proportional to its effective resistance. This lesson states the result and shows it at work; the linear algebra behind it (Laplacians, effective resistance, matrix concentration) is developed in the planned course Spectral Graph Theory.

Laplacians and the spectral guarantee

For a weighted graph GG on nn vertices, the Laplacian is the n×nn \times n matrix

LG=∑e={u,v}∈Ewe bebeT,be=eu−ev,xTLG x=∑{u,v}∈Ewe(xu−xv)2.L_G = \sum_{e = \{u, v\} \in E} w_e\, b_e b_e^{\mathsf{T}}, \qquad b_e = \mathbf{e}_u - \mathbf{e}_v, \qquad x^{\mathsf{T}} L_G\, x = \sum_{\{u, v\} \in E} w_e (x_u - x_v)^2 .

For the indicator vector x=1Sx = \mathbf{1}_S the quadratic form is exactly the cut value w(∂S)w(\partial S). A weighted graph HH on the same vertices is a (1±ε)(1 \pm \varepsilon) spectral sparsifier of GG if

(1−ε) xTLG x  ≤  xTLH x  ≤  (1+ε) xTLG xfor all x∈Rn.(1 - \varepsilon)\, x^{\mathsf{T}} L_G\, x \;\le\; x^{\mathsf{T}} L_H\, x \;\le\; (1 + \varepsilon)\, x^{\mathsf{T}} L_G\, x \qquad \text{for all } x \in \mathbb{R}^n .

Restricting to indicator vectors shows that every spectral sparsifier is a cut sparsifier. The converse fails: there are cut sparsifiers that are far from spectral ones.

Effective resistance

Think of each edge as a resistor of conductance wew_e. The effective resistance ReR_e between the ends of ee is the voltage needed to push one unit of current from uu to vv through the whole network. In matrix terms, with L+L^+ the pseudoinverse,

Re=beTLG+ be.R_e = b_e^{\mathsf{T}} L_G^{+}\, b_e .

weRew_e R_e lies in (0,1](0, 1] and measures how important the edge is: it is 1 for a bridge (all current must use it) and small for an edge with many parallel routes. In fact weRew_e R_e is the probability that ee belongs to a uniformly random spanning tree (for unit weights; Kirchhoff), and Foster's theorem says that these importances add up to n−1n - 1 in every connected graph:

∑e∈EweRe=n−1.\sum_{e \in E} w_e R_e = n - 1 .

The program computes the resistances of a graph made of two dense halves joined by two edges.

python · try it yourself
import random
import numpy as np

def laplacian(n, edges, w):
    L = np.zeros((n, n))
    for (u, v), we in zip(edges, w):
        L[u, u] += we; L[v, v] += we; L[u, v] -= we; L[v, u] -= we
    return L

rng = random.Random(2008)
k = 15
n = 2 * k
edges = []
for off in (0, k):                                   # two dense random halves
    for i in range(k):
        for j in range(i + 1, k):
            if rng.random() < 0.6:
                edges.append((off + i, off + j))
edges += [(0, k), (3, k + 7)]                         # joined by two edges
w = [1.0] * len(edges)
L = laplacian(n, edges, w)
Lp = np.linalg.pinv(L)
R = [Lp[u, u] + Lp[v, v] - 2 * Lp[u, v] for u, v in edges]   # effective resistances
print(f"{n} vertices, {len(edges)} edges")
print(f"Foster's theorem: sum of w_e R_e = {sum(R):.4f} = n - 1 = {n - 1}")
inside = [r for (u, v), r in zip(edges, R) if (u < k) == (v < k)]
print(f"effective resistance: inside a half {min(inside):.3f} .. {max(inside):.3f}, "
      f"the two connecting edges {R[-2]:.3f} and {R[-1]:.3f}")
30 vertices, 129 edges
Foster's theorem: sum of w_e R_e = 29.0000 = n - 1 = 29
effective resistance: inside a half 0.177 .. 0.277, the two connecting edges 0.595 and 0.595

Foster's theorem holds to four decimals. The two connecting edges carry two or three times the resistance of an edge inside a half: they are the edges a sparsifier must not lose.

The Spielman-Srivastava theorem

text
Spectral sparsification by effective resistances (Spielman and Srivastava, 2008)
1  p_e ← w_e R_e / (n − 1)                     (a probability distribution, by Foster)
2  repeat q = C n log n / ε² times:
3      draw an edge e with probability p_e; add weight w_e / (q p_e) to e in H
4  return H

Theorem (Spielman and Srivastava, 2008; stated). For a suitable constant CC, with probability at least 12\frac{1}{2}, HH is a (1±ε)(1 \pm \varepsilon) spectral sparsifier of GG with at most q=O(nlog⁡n/ε2)q = O(n \log n / \varepsilon^2) edges.

About the proof. Each sample adds the rank-one matrix weqpebebeT\frac{w_e}{q p_e} b_e b_e^{\mathsf{T}}, whose expectation over the draw is 1qLG\frac{1}{q} L_G, so E[LH]=LG\mathbb{E}[L_H] = L_G. After the change of basis y=LG1/2xy = L_G^{1/2} x, the condition becomes "all eigenvalues of LG+/2LHLG+/2L_G^{+/2} L_H L_G^{+/2} on the range are in [1−ε,1+ε][1 - \varepsilon, 1 + \varepsilon]", and each sample contributes a positive semidefinite matrix of norm weReqpe=n−1q\frac{w_e R_e}{q p_e} = \frac{n-1}{q}, the same for every edge. That uniform norm bound is exactly what sampling by resistance buys, and a matrix Chernoff bound (Rudelson, 1999; Ahlswede and Winter, 2002; Tropp, 2012) then gives concentration of all eigenvalues at once with q=O(nlog⁡n/ε2)q = O(n \log n/\varepsilon^2) samples. The effective resistances themselves can be approximated in nearly linear time with a Johnson-Lindenstrauss projection and a fast Laplacian solver, which the paper also describes.

The program samples the two-halves graph (now with 30 vertices per half) by resistance and uniformly, with the same number of draws, and measures the spectral error max⁡∣λ−1∣\max \lvert \lambda - 1 \rvert over the eigenvalues λ\lambda of LG+/2LHLG+/2L_G^{+/2} L_H L_G^{+/2} on the range of LGL_G.

python · try it yourself
import random
import numpy as np

def laplacian(n, edges, w):
    L = np.zeros((n, n))
    for (u, v), we in zip(edges, w):
        L[u, u] += we; L[v, v] += we; L[u, v] -= we; L[v, u] -= we
    return L

rng = random.Random(2008)
k = 30
n = 2 * k
edges = []
for off in (0, k):
    for i in range(k):
        for j in range(i + 1, k):
            if rng.random() < 0.9:
                edges.append((off + i, off + j))
edges += [(0, k), (3, k + 7)]
m = len(edges)
L = laplacian(n, edges, [1.0] * m)
Lp = np.linalg.pinv(L)
R = [Lp[u, u] + Lp[v, v] - 2 * Lp[u, v] for u, v in edges]

# whitening: eigenvalues of Lp^(1/2) L_H Lp^(1/2) on the range of L measure the spectral error
vals, vecs = np.linalg.eigh(L)
keep = vals > 1e-9
W = vecs[:, keep] / np.sqrt(vals[keep])               # columns span the range, scaled by lambda^(-1/2)

def spectral_error(LH):
    ev = np.linalg.eigvalsh(W.T @ LH @ W)
    return max(abs(ev[0] - 1), abs(ev[-1] - 1))

def sparsify(probs, q):
    """q samples with replacement; edge e drawn with probability probs[e] gets weight 1/(q probs[e]) per draw."""
    w = [0.0] * m
    for e in rng.choices(range(m), weights=probs, k=q):
        w[e] += 1.0 / (q * probs[e])
    return w

pr = [r / (n - 1) for r in R]                          # Spielman-Srivastava: proportional to w_e R_e
pu = [1.0 / m] * m
print(f"{n} vertices, {m} edges")
print("  samples q | resistance sampling: edges, error | uniform sampling: edges, error, bridges kept")
for q in [200, 600, 2000]:
    wr, wu = sparsify(pr, q), sparsify(pu, q)
    er = spectral_error(laplacian(n, edges, wr))
    eu = spectral_error(laplacian(n, edges, wu))
    print(f"  {q:9} | {sum(x > 0 for x in wr):24}, {er:5.2f} | {sum(x > 0 for x in wu):22}, {eu:5.2f}, "
          f"{sum(x > 0 for x in wu[-2:])} of 2")
60 vertices, 786 edges
  samples q | resistance sampling: edges, error | uniform sampling: edges, error, bridges kept
        200 |                      178,  1.38 |                    177,  1.46, 0 of 2
        600 |                      412,  0.61 |                    411,  0.75, 1 of 2
       2000 |                      720,  0.42 |                    719,  0.80, 2 of 2

Resistance sampling is better at every size. Uniform sampling misses connecting edges (both of them at q=200q = 200, which disconnects the halves and makes the error at least 1, since some vector then has xTLHx=0x^{\mathsf{T}} L_H x = 0). At this small size neither method saves many edges for a useful ε\varepsilon: with n=60n = 60, the bound nlog⁡n/ε2n \log n/\varepsilon^2 exceeds the 786 edges unless ε\varepsilon is large. Sparsifiers pay off for large dense graphs, where O(nlog⁡n/ε2)O(n \log n/\varepsilon^2) is far below Θ(n2)\Theta(n^2).

Better bounds and streams

  • Linear size. Batson, Spielman and Srivastava (2009) proved that O(n/ε2)O(n/\varepsilon^2) edges always suffice, with a deterministic polynomial-time construction ("twice-Ramanujan sparsifiers"), which is optimal up to the constant.
  • Insertion-only streams. Merge-and-reduce, as for cut sparsifiers, gives a one-pass algorithm in O(npolylog⁡n/ε2)O(n \operatorname{polylog} n / \varepsilon^2) space (Kelner and Levin, 2011, sample online with estimated resistances).
  • Dynamic streams. Kapralov, Lee, Musco, Musco and Sidford (2014) gave a single-pass spectral sparsifier from linear sketches in O(npolylog⁡n/ε2)O(n \operatorname{polylog} n/\varepsilon^2) space, building on ℓ2\ell_2-heavy hitters (Count-Sketch) applied to the edge-vertex incidence matrix.
  • Uses: nearly linear time Laplacian solvers (Spielman and Teng), faster max-flow and min-cut algorithms, and graph compression. These are treated in Spectral Graph Theory.

Test yourself

What does a spectral sparsifier preserve that a cut sparsifier need not?

  1. The number of edges
  2. The quadratic form xTLxx^{\mathsf{T}} L x for every real vector xx, not only for 0/1 indicator vectors
  3. Shortest-path distances exactly
  4. Vertex degrees exactly

What does Foster's theorem state?

  1. ∑eRe=m\sum_e R_e = m
  2. ∑eweRe=n−1\sum_e w_e R_e = n - 1 for a connected graph
  3. Every Re≤1/nR_e \le 1/n
  4. Re=1R_e = 1 for every edge of a tree only if nn is even

Why is sampling by effective resistance the right choice for the matrix Chernoff argument?

  1. It is cheaper to compute
  2. Each sampled term weqpebebeT\frac{w_e}{q p_e} b_e b_e^{\mathsf{T}}, after whitening by LG+/2L_G^{+/2}, then has the same norm (n−1)/q(n - 1)/q, which is what matrix concentration needs
  3. It keeps all edges
  4. It makes the samples independent