Spectral Sparsifiers by Effective Resistances
A cut sparsifier preserves for every vertex set . 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 on vertices, the Laplacian is the matrix
For the indicator vector the quadratic form is exactly the cut value . A weighted graph on the same vertices is a spectral sparsifier of if
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 . The effective resistance between the ends of is the voltage needed to push one unit of current from to through the whole network. In matrix terms, with the pseudoinverse,
lies in 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 is the probability that belongs to a uniformly random spanning tree (for unit weights; Kirchhoff), and Foster's theorem says that these importances add up to in every connected graph:
The program computes the resistances of a graph made of two dense halves joined by two edges.
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
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 HTheorem (Spielman and Srivastava, 2008; stated). For a suitable constant , with probability at least , is a spectral sparsifier of with at most edges.
About the proof. Each sample adds the rank-one matrix , whose expectation over the draw is , so . After the change of basis , the condition becomes "all eigenvalues of on the range are in ", and each sample contributes a positive semidefinite matrix of norm , 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 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 over the eigenvalues of on the range of .
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 , which disconnects the halves and makes the error at least 1, since some vector then has ). At this small size neither method saves many edges for a useful : with , the bound exceeds the 786 edges unless is large. Sparsifiers pay off for large dense graphs, where is far below .
Better bounds and streams
- Linear size. Batson, Spielman and Srivastava (2009) proved that 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 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 space, building on -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?
- The number of edges
- The quadratic form for every real vector , not only for 0/1 indicator vectors
- Shortest-path distances exactly
- Vertex degrees exactly
What does Foster's theorem state?
- for a connected graph
- Every
- for every edge of a tree only if is even
Why is sampling by effective resistance the right choice for the matrix Chernoff argument?
- It is cheaper to compute
- Each sampled term , after whitening by , then has the same norm , which is what matrix concentration needs
- It keeps all edges
- It makes the samples independent