A Primer on Lanczos Quadratures

How do you see the spectrum of a Hessian with a hundred million rows? You can't store it, let alone diagonalize it. This primer builds up, from scratch, the tool used in A Defense of the Quadratic Model: stochastic Lanczos quadrature. We start from moment matching, show why the direct solution (Prony's method) breaks, and arrive at Lanczos as the same idea in a better basis. Then we ask how good the answer is.

  1. Motivation
  2. The spectrum as a measure
  3. Probing with a random vector
  4. Moment matching
  5. Prony's trick
  6. The Krylov bridge
  7. Prony breaks
  8. Lanczos: same subspace, better basis
  9. Gram–Schmidt as a three-term recurrence
  10. Reading off nodes and weights
  11. How deep can we see?
  12. Error bands: Gauss–Radau
  13. At scale
  14. Appendix: why one probe suffices

1Motivation

The plan:

  1. Setup: the spectrum as a measure; HVPs give its moments.
  2. Moment matching: the best $m$-atom summary.
  3. Prony: a direct solve (which breaks).
  4. Lanczos: the same idea, stable.
  5. How good is it? Head vs. tail, and error bands.

Running example throughout: $\lambda_i=i^{-1.5}$ for $i=1,\dots,30$ ($d=30$), a power-law spectrum spanning a $160\times$ range.

2The spectrum as a measure

The 30 eigenvalues of the running example as equal-height sticks, with the CDF overlaid
The running example: 30 sticks of mass $1/30$, and the CDF.

How do we compute the moments efficiently?

3Probing the spectrum with a random vector

Probe measure weights for one random probe, and the average over 500 probes, which sits on 1/d
Ground truth for a toy diagonal $H$ ($u_i=e_i$): one probe's weights $(v^\top u_i)^2$ are noisy, but the average over 500 probes sits on $1/d$. Computing this needs all $u_i$, so it is not something we can do in practice.

How do we get $\mu_v$ from its moments?

4Moment matching

Fix one probe $v$. Everything below is deterministic given $v$.

Moment matching with m atoms against the 30 true eigenvalues
m = 1
Running example with $v=\mathbf 1/\sqrt d$, so $\mu_v=\mu_H$. The head is found first; tail atoms carry several eigenvalues' worth of mass. At $m=30$ every eigenvalue is recovered.

How do we solve this nonlinear system?

5Prony's trick: nodes are roots of a polynomial

Exact on paper, but in practice $M_0$ is badly ill-conditioned. Why? Relate it back to $H$.

6The Krylov bridge: Prony's nodes are Ritz values

Prony = Rayleigh–Ritz on $\mathcal K_m$, in the basis $K$. Prony never mentions $H$, but that is what it is doing.

7Prony breaks

Prony nodes against the true Gauss rule, and the condition number of M0 versus m
m = 4
Left: Prony's atoms (orange) against the true Gauss rule (circles). Right: $\kappa(M_0)$ grows exponentially and crosses $1/\epsilon_{\rm mach}$ at $m=8$; beyond that, Prony returns spurious, negative or complex nodes.

The subspace $\mathcal K_m$ is fine; the basis $K$ is terrible. Lanczos: same $\mathcal K_m$, orthonormal basis.

8Lanczos: same subspace, better basis

Ritz values depend only on the subspace $\mathcal K_m$, not on the basis. Fix: keep $\mathcal K_m$, and orthonormalize its basis (Gram–Schmidt).

PronyLanczos
basis of $\mathcal K_m$$K=[\,v,\ Hv,\ \dots\,]$ (nearly parallel)$Q=[\,q_0=v,\ q_1,\ \dots\,]$ (Gram–Schmidt on $K$)
Gram matrix$M_0=K^\top K$: $\kappa\approx10^{16}$$Q^\top Q=I$: $\kappa=1$
Rayleigh–Ritz$y=Kx$: $K^\top HK\,x=\theta\,K^\top K\,x$$y=Qx$: $Q^\top HQ\,x=\theta\,x$
nodes $\vartheta_i$eigenvalues of the pencil $(M_1,M_0)$eigenvalues of $Q^\top HQ$
Gram matrices of the Krylov basis K and the Lanczos basis Q at m=12
$m=12$: the Krylov columns are nearly parallel (Gram matrix all ones), the Lanczos columns are orthonormal (identity).

Same subspace, same nodes. Only the basis differs. How do we compute $Q$?

9Gram–Schmidt as a three-term recurrence

$q_0=v,\ \ q_{-1}=0$start from the probe
for $k=0,\dots,m-1$:
 $w=Hq_k$next Krylov direction (1 HVP)
 $\alpha_k=q_k^\top w$component of $w$ along $q_k$
 $w\leftarrow w-\alpha_kq_k-\beta_{k-1}q_{k-1}$remove components along $q_k,q_{k-1}$ (Gram–Schmidt)
 $\beta_k=\|w\|,\ \ q_{k+1}=w/\beta_k$normalize: a new orthonormal vector
return $\alpha_0,\dots,\alpha_{m-1},\ \beta_0,\dots,\beta_{m-2}$the entries of $T_m$

In exact arithmetic that is the whole algorithm. In floating point, orthogonality is lost as Ritz values converge and "ghost" copies of $\lambda_1$ appear; at scale one stores $Q$ and fully reorthogonalizes (see At scale).

10Reading off nodes and weights

$m$ HVPs → $T_m$ ($m\times m$) → one small eigendecomposition → $\hat\mu_m$.

11How deep can we see? Resolution $\approx\lambda_1/m^2$

  1. Lanczos only sees polynomials of degree $<2m$. Eigenvalues on which all those polynomials agree get lumped together.
  2. Change variables to angles: $\lambda_i=\tfrac{\lambda_1}{2}(1-\cos\varphi_i)$ with $\varphi_i\in[0,\pi]$. By trig identities, every polynomial of degree $\lesssim m$ becomes a cosine sum $\sum_{k\lesssim m}b_k\cos(k\varphi)$.
  3. Near $\lambda=0$ (Taylor): $\cos(k\varphi)\approx1-\tfrac{(k\varphi)^2}{2}$ and $\lambda\approx\tfrac{\lambda_1}{4}\varphi^2$, i.e. $\varphi\approx2\sqrt{\lambda/\lambda_1}$. So:
    • $\lambda\ll\lambda_1/m^2\iff\varphi\ll1/m$: all $\cos(k\varphi)\approx1$, the eigenvalue looks like $\lambda=0$ ⇒ lumped.
    • $\lambda\gg\lambda_1/m^2\iff\varphi\gg1/m$: the cosines vary ⇒ resolved.
Lanczos nodes at m=16 on the running example: top eigenvalues resolved one per node, tail eigenvalues lumped
$\lambda_i=i^{-1.5}$, $d=30$, $m=16$. Node $i$ covers $d\,\omega_i$ eigenvalues. Green: one (resolved). Orange: several (lumped). The top 9 eigenvalues are resolved; the other 21 are lumped into 7 nodes. Dashed: the cutoff, which empirically sits at about $\pi^2\lambda_1/m^2$.

This is a guarantee in terms of eigenvalue size, not count: everything above roughly $\lambda_1/m^2$ is resolved, whatever the spectrum. With $m=1200$ that is a dynamic range of about $1.5\times10^6$.

12Error bands: Gauss–Radau

The $m$-atom solution is unique, but measures with more atoms (including the truth) match the same $2m$ moments. So the number of eigenvalues below a point $\zeta$ is uncertain. For a query point $\zeta$:

  1. Force an atom at $\zeta$: grow $T_m$ by one row and column, $$\tilde T=\begin{pmatrix}T_m & \beta_{m-1}e_m\\ \beta_{m-1}e_m^\top & \gamma\end{pmatrix},$$ with $\gamma$ chosen so that $\zeta$ is an eigenvalue. ($\beta_{m-1}$ is already computed, so this costs no extra HVPs, and $\gamma$ only affects moments of order $\ge2m+1$.)
  2. Eigenvalues of $\tilde T$: $m+1$ new atoms, one of them at $\zeta$, carrying the largest lump the moments allow there.
  3. Band: mass strictly left of $\zeta$ $\le F(\zeta)\le$ mass left of $\zeta$ + lump.
Gauss–Radau band around the count of eigenvalues below a query point, containing the truth
Sweeping $\zeta$ gives a band around the CDF that is guaranteed to contain the truth (Chebyshev–Markov–Stieltjes).

13At scale

Settings used in A Defense of the Quadratic Model:

AAppendix: why one random probe suffices

The probe only affects the weights, and the weights only set the index (x-position) on the index plot, $\lambda_i$ against $i$. The question is whether those x-positions are right.

Left: index plot with one probe versus truth. Right: single weights versus their running average converging to 1
$d=10^4$, $\lambda_i=i^{-1.5}$, one random probe. Left: points shift sideways, visibly only at the head. Right: single weights $d\,(v^\top u_i)^2$ (grey) are noisy; their running average $x/k$ (orange) settles on 1 inside $1\pm\sqrt{2/k}$.