Spectra in Practice

Dive into Deep Learning · §33.4

Spectra in Practice
Gershgorin discs · power iteration & PageRank · non-normal transient growth · Jacobian products · random matrices

Billion-Row Matrices and Misleading Eigenvalues

Motivation

  • Scale Prohibits O(n^3) Factoring: At web or LLM scale, only matrix–vector products \mathbf{A}\mathbf{v} are affordable.
  • Finite-Step Transient Growth: Even when all |\lambda_i| < 1, non-normal powers \|\mathbf{M}^k\|_2 can balloon ten-fold before decaying.
  • Changing BPTT Jacobians: Recurrent backprop multiplies T different matrices \mathbf{D}_1^\top\cdots\mathbf{D}_T^\top where individual eigenvalues promise nothing.

Gershgorin Discs Bound Eigenvalues From Entries

Locating Eigenvalues

  • Row-Sum Discs: For each row i of \mathbf{A}, define disc \mathcal{D}_i with center a_{ii} and radius r_i = \sum_{j \neq i} |a_{ij}|.
  • Three-Line Proof: If \mathbf{A}\mathbf{v} = \lambda\mathbf{v} and |v_i| = \max_j |v_j| > 0, row i gives (\lambda - a_{ii})v_i = \sum_{j \neq i} a_{ij}v_j, so: |\lambda - a_{ii}| \le \sum_{j \neq i} |a_{ij}|\,\frac{|v_j|}{|v_i|} \le r_i
  • Connected Components & Diagonal Dominance: A disjoint union of m discs traps m eigenvalues; if a_{ii} > r_i for all i, 0 \notin \bigcup_i \mathcal{D}_i so \mathbf{A} is invertible (and PD if symmetric).

Verifying Gershgorin Discs on a 3×3 Matrix

Locating Eigenvalues

For \mathbf{A} = \left(\begin{smallmatrix}4&1&0\\-1&4&0.5\\0.5&0&1\end{smallmatrix}\right), the two overlapping discs around 4 trap the complex pair 3.99 \pm 0.96i, while the isolated disc around 1 traps 1.03:

A = np.array([[4.0, 1.0, 0.0],
              [-1.0, 4.0, 0.5],
              [0.5, 0.0, 1.0]])
centres = np.diag(A)
radii = np.abs(A).sum(axis=1) - np.abs(centres)
print('centres:', centres, '  radii:', radii)
for z in np.linalg.eigvals(A):
    print(f'eigenvalue {z:.3f}   distances to the centres: '
          f'{np.abs(z - centres).round(2)}')
centres: [4. 4. 1.]   radii: [1.  1.5 0.5]
eigenvalue 3.987+0.961j   distances to the centres: [0.96 0.96 3.14]
eigenvalue 3.987-0.961j   distances to the centres: [0.96 0.96 3.14]
eigenvalue 1.025+0.000j   distances to the centres: [2.97 2.97 0.03]

Near-Tightness: The complex eigenvalues sit at distance 0.96 from center 4, almost touching the radius-1 boundary of the first disc.

Power Iteration Extracts the Dominant Eigenpair

Computing Eigenvalues at Scale

  • Repeated Multiplication & Normalization: When |\lambda_1| > |\lambda_2| \ge \cdots \ge |\lambda_n| and \mathbf{v}_0 = \sum_i c_i\mathbf{v}_i has c_1 \neq 0, factoring out \lambda_1^k gives: \mathbf{A}^k\mathbf{v}_0 = \lambda_1^k\Bigl(c_1\mathbf{v}_1 + \sum_{i \ge 2} c_i\Bigl(\frac{\lambda_i}{\lambda_1}\Bigr)^k \mathbf{v}_i\Bigr)
  • Linear Direction Rate (|\lambda_2/\lambda_1|^k): Normalizing \mathbf{v}_{k+1} = \mathbf{A}\mathbf{v}_k / \|\mathbf{A}\mathbf{v}_k\| aligns \mathbf{v}_k with \mathbf{v}_1 at geometric rate |\lambda_2/\lambda_1| (1/3 per step on \mathbf{S} = \left(\begin{smallmatrix}2&1\\1&2\end{smallmatrix}\right)).
  • Squared Rayleigh Rate (|\lambda_2/\lambda_1|^{2k}): For symmetric \mathbf{A}, orthogonal eigenvectors make a \delta angle error shift R(\mathbf{v}_k) by only O(\delta^2) (1/9 per step on \mathbf{S}).

Power Iteration in Code and When It Fails

Power Iteration

On a positive 5 \times 5 matrix, 200 power-iteration steps recover |\lambda_1| to 10 decimal places, whereas matrices with a complex conjugate top pair never settle in direction:

A = np.random.rand(5, 5)                 # positive entries
v = np.random.randn(5)
for _ in range(200):
    Av = A @ v
    ratio = np.linalg.norm(Av) / np.linalg.norm(v)
    v = Av / np.linalg.norm(Av)
mods = np.sort(np.abs(np.linalg.eigvals(A)))[::-1]
print(f'norm ratio after 200 steps = {ratio:.10f}')
print(f'largest |eigenvalue|       = {mods[0]:.10f}')
print(f'|lambda_2| / |lambda_1|    = {mods[1] / mods[0]:.3f}')
norm ratio after 200 steps = 2.5254088042
largest |eigenvalue|       = 2.5254088042
|lambda_2| / |lambda_1|    = 0.299

Positive vs. Gaussian Matrices: Across 10{,}000 random 5 \times 5 draws, uniform positive matrices have a real strictly dominant eigenvalue 100\% of the time (gap ratio 0.14–0.37), whereas standard Gaussian matrices have a complex dominant pair \sim 40\% of the time, causing the norm ratio to oscillate forever.

PageRank and the Perron–Frobenius Theorem

Web-Scale Eigenvectors

  • Perron–Frobenius: Any strictly positive matrix has a unique, real, strictly dominant eigenvalue \lambda_1 = \rho(\mathbf{A}) with a positive eigenvector.
  • Damped Google Matrix (\alpha = 0.85): Mixing column-stochastic \mathbf{P} with uniform teleportation \mathbf{G} = \alpha\mathbf{P} + (1-\alpha)\tfrac{1}{n}\mathbf{1}\mathbf{1}^\top breaks dead ends and cycles, bounding |\lambda_2(\mathbf{G})| \le 0.85.
  • Sparse Sweep: Evaluates \mathbf{G}\mathbf{p} = \alpha\mathbf{P}\mathbf{p} + \tfrac{1-\alpha}{n}\mathbf{1} in O(\text{edges}).

The Spectral Radius Governs Only the Distant Limit

Iteration & Stability

  • Gelfand’s Formula: \rho(\mathbf{A}) = \max_i |\lambda_i| = \lim_{k\to\infty} \|\mathbf{A}^k\|^{1/k} sets only the asymptotic k \to \infty rate.
  • Why \rho \le 1 Fails at Finite k: The shear \mathbf{T} has \rho = 1 yet \|\mathbf{T}^k\|_2 \sim k \to \infty, and \mathbf{J}_2(0.99) has \rho = 0.99 < 1 yet climbs to 37 at k = 100.

Normal Matrices vs. Non-Normal Amplification

Normal vs. Non-Normal Maps

  • Normal (\mathbf{A}^\top\mathbf{A} = \mathbf{A}\mathbf{A}^\top): Unitary eigenbasis \mathbf{A} = \mathbf{U}\boldsymbol{\Lambda}\mathbf{U}^* guarantees \|\mathbf{A}^k\|_2 = \rho(\mathbf{A})^k at every step k.
  • Non-Normal Bound: When eigenvectors are non-orthogonal, \|\mathbf{A}^k\|_2 \le \kappa_2(\mathbf{V})\rho(\mathbf{A})^k.
  • Unraveling Cancellation: Nearly parallel eigenvectors (\kappa_2(\mathbf{V}) \gg 1) cause huge cancelling components at k = 0 to decouple at finite k.

Transient Growth From Nearly Parallel Eigenvectors

Non-Normal Dynamics

  • Distinct Eigenvalues Inside the Unit Disc: \mathbf{M} = \left(\begin{smallmatrix}0.9&4\\0&0.8\end{smallmatrix}\right) has \lambda_1 = 0.9 and \lambda_2 = 0.8, with eigenvectors \mathbf{v}_1 = (1, 0) and \mathbf{v}_2 = (-40, 1) separated by only 1.4^\circ.
  • Unraveling Cancellation: Writing \mathbf{e}_2 = (0, 1) = 40\mathbf{v}_1 + \mathbf{v}_2 gives: \mathbf{M}^k\mathbf{e}_2 = \begin{bmatrix}40(0.9^k - 0.8^k) \\ 0.8^k\end{bmatrix}
  • Ten-Fold Peak at k = 6: Because 0.8^k decays faster than 0.9^k, the difference peaks at \|\mathbf{M}^6\|_2 \approx 10.8 before decaying.

Comparing Non-Normal M Against Normal Λ in Code

Non-Normal Dynamics

Even though \mathbf{M} = \left(\begin{smallmatrix}0.9&4\\0&0.8\end{smallmatrix}\right) and \boldsymbol{\Lambda} = \operatorname{diag}(0.9, 0.8) share the exact same eigenvalues, \boldsymbol{\Lambda}^k contracts monotonically from step 1 while \mathbf{M}^k amplifies ten-fold:

M = np.array([[0.9, 4.0], [0.0, 0.8]])
Lam = np.diag([0.9, 0.8])                   # same eigenvalues, normal
lam, V = np.linalg.eig(M)                   # unit eigenvectors as columns
print('eigenvalues:', lam)
print('coefficients of e_2 on the unit eigenvectors:',
      np.linalg.solve(V, [0., 1.]))
ks = np.arange(61)
norm_M = [np.linalg.norm(np.linalg.matrix_power(M, k), 2) for k in ks]
norm_L = [np.linalg.norm(np.linalg.matrix_power(Lam, k), 2) for k in ks]
k_peak = int(np.argmax(norm_M))
print(f'max ||M^k|| = {norm_M[k_peak]:.3f} at k = {k_peak};  '
      f'max ||Lambda^k|| = {max(norm_L):.3f}')
print(f'kappa_2(V) = {np.linalg.cond(V):.1f}')
eigenvalues: [0.9 0.8]
coefficients of e_2 on the unit eigenvectors: [40.         40.01249805]
max ||M^k|| = 10.788 at k = 6;  max ||Lambda^k|| = 1.000
kappa_2(V) = 80.0

Pseudospectra and Eigenvalue Sensitivity

Non-Normal Diagnostics

  • \varepsilon-Pseudospectrum \Lambda_\varepsilon(\mathbf{A}): The set of all z \in \mathbb{C} that are eigenvalues of \mathbf{A} + \mathbf{E} for some perturbation \|\mathbf{E}\|_2 \le \varepsilon, equivalently where the resolvent norm satisfies: \|(z\mathbf{I} - \mathbf{A})^{-1}\|_2 \ge \frac{1}{\varepsilon}
  • Normal Discs vs. Non-Normal Bulge: At z = 1, \|(\mathbf{I} - \boldsymbol{\Lambda})^{-1}\|_2 = 1/(1 - 0.9) = 10, whereas \|(\mathbf{I} - \mathbf{M})^{-1}\|_2 = 200.3: a tiny perturbation of size \varepsilon \approx 0.005 pushes an eigenvalue of \mathbf{M} onto the unit circle.

Products of Changing Jacobians in Recurrent Networks

Backpropagation Through Time

  • Changing Jacobians in BPTT: Backprop multiplies T distinct per-step matrices \nabla_{\mathbf{h}_0}\mathcal{L} = \mathbf{D}_1^\top\mathbf{D}_2^\top\cdots\mathbf{D}_T^\top\nabla_{\mathbf{h}_T}\mathcal{L}.
  • Zero Spectral Radius Can Still Explode: Nilpotent \mathbf{D}_1 = \left(\begin{smallmatrix}0&2\\0&0\end{smallmatrix}\right) and \mathbf{D}_2 = \left(\begin{smallmatrix}0&0\\2&0\end{smallmatrix}\right) both have \rho = 0, yet \mathbf{D}_2\mathbf{D}_1 = \operatorname{diag}(0, 4) has \rho = 4 and explodes as 4^{T/2}.

Three Quantities for Iterated Linear Maps

Stability Hierarchy

  • Spectral Radius \rho(\mathbf{A}): Asymptotic k \to \infty growth rate of powers of one fixed matrix.
  • Spectral Norm \|\mathbf{A}\|_2 = \sigma_1: Worst-case 1-step stretch; bounds finite products \|\mathbf{D}_T\cdots\mathbf{D}_1\|_2 \le \prod_t \|\mathbf{D}_t\|_2.
  • Top Lyapunov Exponent \mu: Long-run exponential rate \lim_{T\to\infty}\frac{1}{T}\log\|\mathbf{D}_T\cdots\mathbf{D}_1\mathbf{x}_0\| of changing matrices.

Random Weight Matrices at Initialization

Random Matrix Theory

  • Circular Law vs. 2\times Stretch: An n \times n Gaussian matrix has \rho(\mathbf{A}) \approx \sqrt{n} but maximum stretch \|\mathbf{A}\|_2 \approx 2\sqrt{n}.
  • Deep Product Paradox (\mu < 0): Fan-in scaling \mathcal{N}(0, 1/n) preserves \mathbb{E}\|\mathbf{D}\mathbf{x}\|^2 = \|\mathbf{x}\|^2, yet concavity of \log causes deep products to shrink at rate \mu \approx -1/(2n).
n = 1000
A = np.random.randn(n, n)
print(f'rho(A) / sqrt(n)       = {np.abs(np.linalg.eigvals(A)).max() / n ** 0.5:.3f}')
print(f'sigma_max(A) / sqrt(n) = {np.linalg.norm(A, 2) / n ** 0.5:.3f}')
rho(A) / sqrt(n)       = 1.030
sigma_max(A) / sqrt(n) = 1.990

Why Deep Learning Needs Singular Values Next

Bridge to SVD

  • Four Gaps Eigenvalues Cannot Fill: Rectangular layers (m \neq n), defective shears, non-normal transient growth, and the 2\times stretch gap in random Gaussian weights.
  • The SVD Remedy (§33.5): Separate orthonormal input (\mathbf{V}) and output (\mathbf{U}) bases decompose every matrix into non-negative stretches \sigma_1 \ge \sigma_2 \ge \cdots \ge 0.

Concept Check: Discs, Power Iteration & Stability

Concept Check

  1. Gershgorin Invertibility: Use Gershgorin discs to explain at a glance why \mathbf{A} = \left(\begin{smallmatrix}5&-1&1\\2&6&-1\\0&1&4\end{smallmatrix}\right) is guaranteed to be invertible without computing its determinant.
  2. Power Iteration Rate: For symmetric \mathbf{S} with eigenvalues \lambda_1 = 3 and \lambda_2 = 1, by what factor does the Rayleigh quotient error 3 - R(\mathbf{v}_k) shrink per power-iteration step?
  3. Spectral Radius vs. Norm: Does \rho(\mathbf{A}) \le 1 guarantee that \|\mathbf{A}^k\|_2 stays bounded for all k \ge 1? Give a 2 \times 2 counterexample.

Answers: 1. The three row discs have centers 5, 6, 4 and radii 2, 3, 1; since a_{ii} > r_i in every row, all discs lie strictly in \operatorname{Re}(z) \ge 3 > 0, so 0 cannot be an eigenvalue and \mathbf{A} is invertible. 2. Direction error shrinks by |\lambda_2/\lambda_1| = 1/3 per step, while the Rayleigh quotient error shrinks at the squared rate (1/3)^2 = 1/9 per step. 3. No: the defective shear \mathbf{T} = \left(\begin{smallmatrix}1&1\\0&1\end{smallmatrix}\right) has \rho(\mathbf{T}) = 1, yet \mathbf{T}^k = \left(\begin{smallmatrix}1&k\\0&1\end{smallmatrix}\right) has \|\mathbf{T}^k\|_2 \sim k \to \infty.

Summary: Spectra in Practice

Key Takeaways

  • Locating & Extracting Eigenvalues: Gershgorin discs bound spectra in O(n^2), power iteration converges at |\lambda_2/\lambda_1|^k, and PageRank damping caps |\lambda_2(\mathbf{G})| \le 0.85.
  • Stability Beyond Eigenvalues: Non-normal matrices grow up to \kappa_2(\mathbf{V})\rho(\mathbf{A})^k, changing BPTT Jacobians require spectral norms and gates, and Gaussian matrices stretch by 2\sqrt{n}.