TExcelTAD
Home › Spectral Graph Theory & Modern Graph Algorithms › Sparsification by Effective Resistances

Sparsification by Effective Resistances

A spectral sparsifier of a graph GG is a sparse weighted graph HH on the same vertices whose Laplacian quadratic form is within a factor 1±ε1 \pm \varepsilon of GG's for every vector. The lesson Spectral Sparsifiers by Effective Resistances in the streaming course stated the Spielman-Srivastava theorem and ran it. Here we open the box: the linear algebra that makes effective resistances the right sampling weights, the matrix concentration bound behind the theorem, how to estimate all resistances quickly with a random projection, and the deterministic linear-size construction of Batson, Spielman and Srivastava, implemented on a small example.

Spectral approximation

Write LH⪯LGL_H \preceq L_G if xTLHx≤xTLGxx^{\mathsf{T}} L_H x \le x^{\mathsf{T}} L_G x for all xx (the Loewner order). HH is a (1±ε)(1 \pm \varepsilon)-spectral sparsifier of GG if

(1−ε)LG⪯LH⪯(1+ε)LG.(1 - \varepsilon) L_G \preceq L_H \preceq (1 + \varepsilon) L_G .

By Courant-Fischer this implies that every eigenvalue, every cut (x=1Sx = \mathbf{1}_S), every effective resistance (up to 1±O(ε)1 \pm O(\varepsilon)) and the solution of every Laplacian system are approximately preserved; and LHL_H is a preconditioner with relative condition number 1+ε1−ε\frac{1 + \varepsilon}{1 - \varepsilon}. Spielman and Teng (2004) introduced the notion, with sparsifiers of O(nlog⁡cn/ε2)O(n\log^c n/\varepsilon^2) edges, as an ingredient of their solver. For G=KnG = K_n a sparsifier is an expander: the Ramanujan graphs of the constructions lesson are, after scaling, sparsifiers of the complete graph with ε≈2/d\varepsilon \approx 2/\sqrt d.

Leverage scores and the projection Π\Pi

Let BB be the m×nm \times n incidence matrix and WW the diagonal edge weights, so L=BTWBL = B^{\mathsf{T}} W B. Define the m×mm \times m matrix

Π=W1/2B L+BTW1/2,Πee=we beTL+be=weReff(e).\Pi = W^{1/2} B\, L^+ B^{\mathsf{T}} W^{1/2}, \qquad \Pi_{ee} = w_e\, b_e^{\mathsf{T}} L^+ b_e = w_e R_{\text{eff}}(e) .

Π\Pi is the orthogonal projection onto the column space of W1/2BW^{1/2}B (check: Π2=W1/2BL+(BTWB)L+BTW1/2=Π\Pi^2 = W^{1/2}BL^+(B^{\mathsf{T}}WB)L^+B^{\mathsf{T}}W^{1/2} = \Pi), which has dimension n−1n - 1. Its diagonal entries are the leverage scores weReff(e)∈(0,1]w_e R_{\text{eff}}(e) \in (0, 1], and tr⁡Π=n−1\operatorname{tr}\Pi = n - 1 is Foster's theorem again. In statistics language, sparsification is row sampling of the matrix W1/2BW^{1/2}B by leverage scores, a technique that also underlies fast least-squares solvers.

Whitening makes the role of the leverage scores clear. With ye=we L+/2bey_e = \sqrt{w_e}\, L^{+/2} b_e,

∑eyeyeT=L+/2LGL+/2=Irange,∥ye∥2=weReff(e).\sum_e y_e y_e^{\mathsf{T}} = L^{+/2} L_G L^{+/2} = I_{\text{range}}, \qquad \lVert y_e \rVert^2 = w_e R_{\text{eff}}(e) .

HH is a (1±ε)(1 \pm \varepsilon)-sparsifier exactly when its reweighted sum ∑eseyeyeT\sum_e s_e y_ey_e^{\mathsf{T}} has all eigenvalues (on the range) in [1−ε,1+ε][1 - \varepsilon, 1 + \varepsilon]. So sparsification is the problem of approximating the identity by a few of the rank-one matrices yeyeTy_ey_e^{\mathsf{T}}, and an edge's leverage score is its "share" of the identity.

python · try it yourself
import numpy as np

# two 5-cliques joined by a bridge (4-5) plus one extra edge (0-9) between them
edges = [(a + s, b + s) for s in (0, 5) for a in range(5) for b in range(a + 1, 5)] + [(4, 5), (0, 9)]
n, m = 10, len(edges)
B = np.zeros((m, n))
for i, (u, v) in enumerate(edges):
    B[i, u], B[i, v] = 1, -1
L = B.T @ B
Pi = B @ np.linalg.pinv(L) @ B.T
lev = np.diag(Pi)
print("Pi is a projection:", bool(np.allclose(Pi @ Pi, Pi)), "  trace =", round(float(np.trace(Pi)), 6), "= n - 1")
print("leverage scores inside a clique:", np.round(lev[:3], 4) + 0.0)
print("leverage of the two connecting edges 4-5 and 0-9:", np.round(lev[-2:], 4) + 0.0)
Pi is a projection: True   trace = 9.0 = n - 1
leverage scores inside a clique: [0.3857 0.3857 0.3857]
leverage of the two connecting edges 4-5 and 0-9: [0.6429 0.6429]

The two connecting edges each carry leverage about 0.640.64, against 0.390.39 for an edge inside a clique, whose ends are joined by many parallel routes. A sparsifier that dropped both connecting edges would disconnect the halves, so they must be sampled with high probability; uniform sampling would treat all 22 edges alike.

The Spielman-Srivastava theorem, with the concentration step

Theorem (Spielman and Srivastava, 2008; journal version 2011). Sample qq edges independently with replacement, edge ee with probability pe=weReff(e)n−1p_e = \frac{w_eR_{\text{eff}}(e)}{n-1}, and give each sampled copy weight weqpe\frac{w_e}{qp_e}. If q≥Cnlog⁡nε2q \ge C\frac{n\log n}{\varepsilon^2} for a suitable absolute constant CC, then HH is a (1±ε)(1 \pm \varepsilon)-sparsifier of GG with probability at least 1−1n1 - \frac1n.

Proof outline. The ii-th sample contributes the random matrix Xi=1qpeyeyeTX_i = \frac{1}{qp_e}y_ey_e^{\mathsf{T}} (in whitened coordinates). Then E[Xi]=1q∑eyeyeT=1qI\mathbb{E}[X_i] = \frac1q\sum_e y_ey_e^{\mathsf{T}} = \frac1q I, and because pep_e is proportional to ∥ye∥2\lVert y_e \rVert^2, every possible XiX_i has the same norm ∥ye∥2qpe=n−1q\frac{\lVert y_e \rVert^2}{qp_e} = \frac{n-1}{q}. The matrix Chernoff bound (Tropp, 2012, building on Rudelson, 1999, and Ahlswede and Winter, 2002) says: for independent positive semidefinite d×dd \times d matrices XiX_i with ∥Xi∥≤R\lVert X_i \rVert \le R and ∑iEXi=I\sum_i\mathbb{E}X_i = I,

Pr⁡[λmin⁡(∑iXi)≤1−ε  or  λmax⁡(∑iXi)≥1+ε]≤2d e−ε2/(3R)(0<ε<1).\Pr\Big[\lambda_{\min}\big(\textstyle\sum_i X_i\big) \le 1 - \varepsilon \ \text{ or } \ \lambda_{\max}\big(\textstyle\sum_i X_i\big) \ge 1 + \varepsilon\Big] \le 2d\, e^{-\varepsilon^2/(3R)} \qquad (0 < \varepsilon < 1).

With d=n−1d = n - 1 and R=(n−1)/qR = (n-1)/q, the failure probability is below 1n\frac1n once q≥3(n−1)ln⁡(2n2)/ε2q \ge 3(n-1)\ln(2n^2)/\varepsilon^2. □\square

Sampling by any upper bounds R~e≥Reff(e)\tilde R_e \ge R_{\text{eff}}(e) also works, with qq multiplied by ∑eweR~e/(n−1)\sum_e w_e\tilde R_e/(n-1). Koutis, Miller and Peng used tree stretch as such an upper bound, which needs no solver at all.

Estimating all resistances at once

Computing L+L^+ costs O(n3)O(n^3). Spielman and Srivastava observed that

Reff(u,v)=∥W1/2BL+(eu−ev)∥2,R_{\text{eff}}(u, v) = \big\lVert W^{1/2} B L^+ (\mathbf{e}_u - \mathbf{e}_v) \big\rVert^2 ,

a squared distance between columns of the m×nm \times n matrix W1/2BL+W^{1/2}BL^+. By the Johnson-Lindenstrauss lemma, multiplying on the left by a random k×mk \times m matrix QQ with entries ±1/k\pm 1/\sqrt k, k=O(log⁡n/ε2)k = O(\log n/\varepsilon^2), preserves all these distances within 1±ε1 \pm \varepsilon. Computing Z=QW1/2BL+Z = QW^{1/2}BL^+ needs only kk Laplacian solves (one per row: Lzi=BTW1/2qiL z_i = B^{\mathsf{T}}W^{1/2}q_i), so all mm resistances are approximated in O~(mlog⁡n/ε2)\tilde O(m\log n/\varepsilon^2) time with a nearly-linear solver.

python · try it yourself
import numpy as np

rng = np.random.default_rng(2008)
n = 60
edges = [(u, v) for u in range(n) for v in range(u + 1, n) if rng.random() < 0.15]
m = len(edges)
B = np.zeros((m, n))
for i, (u, v) in enumerate(edges):
    B[i, u], B[i, v] = 1, -1
L = B.T @ B
Lp = np.linalg.pinv(L)
exact = np.array([Lp[u, u] + Lp[v, v] - 2 * Lp[u, v] for u, v in edges])
print(f"n = {n}, m = {m}; exact resistances from {exact.min():.4f} to {exact.max():.4f}")
for k in [24, 96, 384]:
    Q = rng.choice([-1.0, 1.0], size=(k, m)) / np.sqrt(k)
    Z = (Q @ B) @ Lp                          # in a real solver: k Laplacian solves, one per row
    approx = np.array([float(np.sum((Z[:, u] - Z[:, v]) ** 2)) for u, v in edges])
    rel = np.abs(approx / exact - 1)
    print(f"k = {k:3} random rows: median relative error {np.median(rel):.3f}, worst {rel.max():.3f}")
n = 60, m = 258; exact resistances from 0.1466 to 0.5592
k =  24 random rows: median relative error 0.211, worst 0.920
k =  96 random rows: median relative error 0.113, worst 0.486
k = 384 random rows: median relative error 0.053, worst 0.207

The error shrinks like 1/k1/\sqrt k, as the Johnson-Lindenstrauss lemma predicts. For sampling, a constant-factor approximation of each resistance is enough (it only changes qq by a constant), so a small kk suffices.

Linear-size sparsifiers: Batson-Spielman-Srivastava

Sampling needs Θ(nlog⁡n)\Theta(n\log n) edges because of the coupon-collector effect. Batson, Spielman and Srivastava (2009; journal 2012) removed the logarithm with a deterministic barrier-potential argument.

Theorem (Batson, Spielman and Srivastava, 2009). For every d>1d > 1, every graph has a weighted subgraph HH with at most ⌈d(n−1)⌉\lceil d(n-1) \rceil edges such that LG⪯LH⪯κLGL_G \preceq L_H \preceq \kappa L_G (after scaling), with

κ=d+1+2dd+1−2d,\kappa = \frac{d + 1 + 2\sqrt d}{d + 1 - 2\sqrt d},

and HH can be found in polynomial time. For G=KnG = K_n this gives graphs with average degree 2d2d and condition number about 1+4/d1 + 4/\sqrt d: comparable to Ramanujan graphs, which achieve it with half as many edges. Hence the name twice-Ramanujan sparsifiers. Lee and Sun (2017) found a nearly-linear-time construction of linear-size sparsifiers.

The algorithm adds one rank-one matrix t yeyeTt\,y_ey_e^{\mathsf{T}} at a time to AA (starting from A=0A = 0) while keeping all eigenvalues of AA strictly between a lower barrier ℓ\ell and an upper barrier uu that both move right by fixed amounts each step. The potentials Φu(A)=tr⁡(uI−A)−1\Phi^u(A) = \operatorname{tr}(uI - A)^{-1} and Φℓ(A)=tr⁡(A−ℓI)−1\Phi_\ell(A) = \operatorname{tr}(A - \ell I)^{-1} measure how close the eigenvalues are to the barriers; a short averaging argument shows that some edge and weight always keep both potentials from growing. After d(n−1)d(n-1) steps the ratio u/ℓu/\ell is at most κ\kappa.

python · try it yourself
import numpy as np

rng = np.random.default_rng(1)
n = 30
edges = [(u, v) for u in range(n) for v in range(u + 1, n) if rng.random() < 0.8]   # a dense random graph
m, N = len(edges), n - 1
L = np.zeros((n, n))
for u, v in edges:
    L[u, u] += 1; L[v, v] += 1; L[u, v] -= 1; L[v, u] -= 1
vals, vecs = np.linalg.eigh(L)
Qw = vecs[:, 1:] / np.sqrt(vals[1:])                                 # whitening on the range of L
Y = np.array([Qw[u] - Qw[v] for u, v in edges])                       # y_e, with sum y_e y_e^T = I

def condition(weights):
    LH = np.zeros((n, n))
    for (u, v), w in zip(edges, weights):
        LH[u, u] += w; LH[v, v] += w; LH[u, v] -= w; LH[v, u] -= w
    ev = np.linalg.eigvalsh(Qw.T @ LH @ Qw)
    return float(ev[-1] / ev[0]) if ev[0] > 1e-9 else float("inf")

def bss(d):
    eps_l, eps_u = 1 / np.sqrt(d), (np.sqrt(d) - 1) / (d + np.sqrt(d))
    step_l, step_u = 1.0, (np.sqrt(d) + 1) / (np.sqrt(d) - 1)
    low, up = -N / eps_l, N / eps_u
    A, s, I = np.zeros((N, N)), np.zeros(m), np.eye(N)
    for _ in range(int(d * N)):
        up2, low2 = up + step_u, low + step_l
        Ui, Li = np.linalg.inv(up2 * I - A), np.linalg.inv(A - low2 * I)
        dphi_u = np.trace(np.linalg.inv(up * I - A)) - np.trace(Ui)
        dphi_l = np.trace(Li) - np.trace(np.linalg.inv(A - low * I))
        quad = lambda M: np.einsum("ij,jk,ik->i", Y, M, Y)
        U = quad(Ui @ Ui) / dphi_u + quad(Ui)                         # need 1/t >= U(y_e)
        Lo = quad(Li @ Li) / dphi_l - quad(Li)                        # and  1/t <= L(y_e)
        e = int(np.argmax(np.round(Lo - U, 9)))                       # an edge with U <= L exists
        t = 2 / (U[e] + Lo[e])
        A += t * np.outer(Y[e], Y[e]); s[e] += t
        up, low = up2, low2
    return s

lev = (Y ** 2).sum(axis=1)                                            # leverage scores, sum n - 1
p = lev / lev.sum()
print(f"G(30, 0.8): {m} edges")
for d in [3, 6]:
    s = bss(d)
    k = int((s > 0).sum())
    w = np.zeros(m)
    for e in rng.choice(m, size=k, p=p):                              # same budget, Spielman-Srivastava
        w[e] += 1 / (k * p[e])
    bound = (d + 1 + 2 * np.sqrt(d)) / (d + 1 - 2 * np.sqrt(d))
    print(f"d = {d}: BSS keeps {k} edges, condition number {condition(s):.3f} (guarantee {bound:.3f}); "
          f"resistance sampling with {k} draws: {condition(w):.3f}")
G(30, 0.8): 353 edges
d = 3: BSS keeps 87 edges, condition number 3.072 (guarantee 13.928); resistance sampling with 87 draws: inf
d = 6: BSS keeps 174 edges, condition number 2.023 (guarantee 5.663); resistance sampling with 174 draws: 5.705

With the same edge budget, the barrier method's sparsifier is better conditioned than resistance sampling, and far better than its own worst-case guarantee. With only 87 draws, sampling even leaves the graph disconnected (condition number infinite): some vertex lost all its edges, the coupon-collector effect behind the log⁡n\log n. Sampling with replacement also wastes part of its budget on repeated edges.

Test yourself

What is the leverage score of edge ee in sparsification?

  1. Its weight wew_e
  2. weReff(e)w_e R_{\text{eff}}(e), the diagonal entry Πee\Pi_{ee} of the projection W1/2BL+BTW1/2W^{1/2}BL^+B^{\mathsf{T}}W^{1/2}
  3. The degree of its endpoints
  4. 1/m1/m

Why does sampling proportionally to weReff(e)w_eR_{\text{eff}}(e) suit the matrix Chernoff bound?

  1. It minimizes the number of distinct edges
  2. Every sampled whitened term then has the same norm (n−1)/q(n-1)/q, the smallest possible maximum norm
  3. It makes the samples deterministic
  4. It avoids computing L+L^+

How can all effective resistances be approximated quickly?

  1. By computing L+L^+ exactly
  2. By projecting W1/2BL+W^{1/2}BL^+ with a random k×mk \times m matrix, k=O(log⁡n/ε2)k = O(\log n/\varepsilon^2), which needs only kk Laplacian solves
  3. By BFS
  4. By counting spanning trees

What did Batson, Spielman and Srivastava (2009) achieve?

  1. Sparsifiers with O(nlog⁡n/ε2)O(n\log n/\varepsilon^2) edges by sampling
  2. Deterministic sparsifiers with ⌈d(n−1)⌉\lceil d(n-1) \rceil edges and condition number d+1+2dd+1−2d\frac{d+1+2\sqrt d}{d+1-2\sqrt d}, i.e. O(n/ε2)O(n/\varepsilon^2) edges
  3. Exact cut sparsifiers
  4. Sparsifiers of directed graphs