Eigenvalues, Eigenvectors, Diagonalization & Spectral Theory
Invariant axes Av = λv, trace/det shortcuts, matrix powers A^k, Spectral Theorem for covariance matrices, PSD curvature, and Power Iteration
Eigenvectors power PCA dimensionality reduction, Google PageRank, Graph Neural Networks, and diagnosing Deep Learning saddle points!
Hessian eigenvalues reveal whether your neural net hit a flat minimum (generalizes well!), a sharp minimum, or a saddle point (mixed + and − eigenvalues!).
PCA literally computes the top eigenvectors of your dataset's Covariance Matrix Σ — automatically finding the perpendicular axes capturing 95%+ of your data's variance!
'What are the eigenvectors and eigenvalues of a Covariance Matrix?' and 'How does Power Iteration find the dominant eigenvector of a billion-node graph?' are staple ML interviews!
When you multiply almost any arrow v by a matrix A, it BOTH rotates to a new angle AND changes length. What makes a special arrow v an EIGENVECTOR of A?
- Distinguish regular vectors from eigenvectors geometrically and solve det(A − λI) = 0 using trace & determinant shortcuts.
- Diagonalize A = PΛP⁻¹ to compute high matrix powers A^k = PΛ^k P⁻¹ (and understand RNN exploding/vanishing gradients!).
- Apply the Spectral Theorem to real symmetric & Positive Semi-Definite (PSD) matrices (covariance matrices, Hessians).
- Implement Power Iteration & the Rayleigh Quotient to extract the dominant eigenpair in O(k·n²).
An eigenvector is a hidden symmetry axis of matrix : applying only stretches or flips by its eigenvalue (). Discovering these axes untangles complex coupled dynamics into simple independent 1D scalings!
1. Geometric Meaning, det(A − λI) = 0 & Trace/Det Shortcuts
Picture stretching a rubber sheet unevenly: almost every arrow drawn on the sheet gets twisted sideways to a brand-new angle. Yet hidden inside the matrix are special magic directions that stay pointing along the EXACT same ray — they ONLY get stretched or shrunk! Hunt down a live eigenvector by spinning the arrow below until blue and purple snap together!
We seek non-zero vectors such that . For a non-zero solution to exist, must be singular:
Two Golden Sanity-Check Laws
- Sum of eigenvalues = Trace: (sum of diagonal entries).
- Product of eigenvalues = Determinant: .
Worked Example 1 — 2×2 Eigenpairs & Diagonalization
Let :
- and .
- Eigenvectors: and .
- Instant Matrix Powers (): Since with : (That's also why RNNs explode when and vanish when over timesteps!)
Most input arrows (blue) get knocked off course into a different angle (violet) when multiplied by matrix A. Spin the angle slider until both arrows line up on the EXACT same ray — THAT special direction is an Eigenvector!
Use the Trace & Determinant shortcut to find both eigenvalues of A = [[5, 2], [2, 5]] in under 10 seconds!
2. The Spectral Theorem, Positive Semi-Definite (PSD) Matrices & PCA
Imagine a cloud of 10,000 customers plotted by Income and Annual Spend — it forms a tilted football shape! Which single axis summarizes the football best? Its longest principal axis (the top eigenvector of Covariance Σ)! And because Σ is symmetric, the Spectral Theorem guarantees ALL Principal Components are 100% real and 90° perpendicular to each other!
For any real symmetric matrix (), the Spectral Theorem guarantees:
- All eigenvalues are real.
- Eigenvectors form an orthonormal basis ().
- .
A symmetric matrix is Positive Semi-Definite (PSD, ) if for all every eigenvalue .
- Every sample covariance matrix is guaranteed PSD because !
- PCA in one line: The top eigenvector of is the exact direction of maximum variance (), and captures the next largest variance ()!
Why Covariance eigenvectors are literally the Principal Components of your dataset!
Captures how every pair of centered features wiggles together — always symmetric & Positive Semi-Definite!
Is the symmetric matrix M = [[2, 3], [3, 2]] Positive Semi-Definite (PSD)?
3. Hessian Curvature & Power Iteration (PageRank)
How do you tell if a deep learning optimizer stopped at a true bottom (minimum), a hilltop (maximum), or a Pringle-chip saddle point? Check the signs of the Hessian's eigenvalues: all + = valley floor, all − = hilltop, mixed + and − = saddle point (which dominates 99.9% of flat spots in high-dimensional neural nets!).
In optimization, the Hessian is symmetric, so its eigenvalues classify any stationary point ():
- All (PD): Strict local minimum.
- All (ND): Strict local maximum.
- Mixed positive & negative : Saddle point (overwhelmingly common in high-dimensional deep neural networks!).
Power Iteration for Huge Matrices
When is huge (like Google's PageRank graph), computing all eigenpairs is impossible. Repeating: converges exponentially at rate straight to the dominant eigenpair!
Pause & Check: A 3×3 Covariance matrix has eigenvalues λ₁ = 7, λ₂ = 2, λ₃ = 1. If you compress the dataset from 3D down to 2D using PCA, what percentage of total variance do you KEEP?
A 2×2 matrix has eigenvalues λ₁ = 6 and λ₂ = 2. After k = 3 steps of Power Iteration, by what factor has the λ₂ component shrunk relative to λ₁?
The exact honest questions almost every beginner wonders — answered in plain English without hiding behind jargon.
Aha! Think about spinning a clock hand 90°: EVERY arrow on the plane turns 90° — NO arrow stays on its own line! That's why a 90° rotation has no real eigenvectors (its eigenvalues are imaginary ±i)! That's also why Symmetric matrices (like Covariance Σ and Hessians) are so beloved in ML: the Spectral Theorem guarantees they ALWAYS have 100% real, perpendicular eigenvectors!
Principal Component Analysis (PCA)
Principal components are the orthogonal eigenvectors of Σ ordered by eigenvalues λ₁ ≥ λ₂ ≥ … representing exact variance along each axis.
Hessian Eigenvalues & Saddle Points
In 100M-parameter networks, the probability that all 100M Hessian eigenvalues have the same sign is vanishingly small — explaining why SGD escapes saddles rather than getting stuck in bad local minima.
RNN Exploding & Vanishing Gradients
Backpropagating T steps multiplies by W_hᵀ repeatedly — governed directly by |λ_max(W_h)|^T.
Google PageRank & Markov Steady States
Stochastic transition matrices have dominant eigenvalue λ₁ = 1 whose eigenvector π (Pπ = π) gives the stationary distribution.
import numpy as np
Sigma = np.array([[2.0, 0.8],
[0.8, 1.2]])
# ALWAYS use eigh (not eig) for symmetric matrices -> real sorted eigenvalues!
eigvals, eigvecs = np.linalg.eigh(Sigma)
idx = np.argsort(eigvals)[::-1]
eigvals, eigvecs = eigvals[idx], eigvecs[:, idx]
# Power Iteration + Rayleigh Quotient:
v = np.array([1.0, 0.0])
for _ in range(25):
v = Sigma @ v
v /= np.linalg.norm(v)
lam_max = float(v @ Sigma @ v) # ≈ 2.4944