P = np.array([[0.5, 0.25], [0.5, 0.75]])
lam, V = np.linalg.eig(P)
print('eigenvalues:', lam)
print('eigenvectors (columns):\n', V)
print('max |P V - V diag(lam)|:', np.abs(P @ V - V * lam).max())Dive into Deep Learning · §33.3
Eigendecompositions
eigenvectors · diagonalization & matrix powers · defective & complex spectra · spectral theorem · quadratic forms
Motivation
Core Definition
Characteristic Polynomial
eigenvalues: [0.25 1. ]
eigenvectors (columns):
[[-0.70710678 -0.4472136 ]
[ 0.70710678 -0.89442719]]
max |P V - V diag(lam)|: 0.0
Numerical Eigensolvers
Diagonalization
Diagonalization in Code
Fifty matrix multiplications \mathbf{P}^{50}\mathbf{p}_0 and the scalar power formula \sum_i c_i \lambda_i^{50}\mathbf{v}_i match to machine precision, with consecutive errors dividing by 4 at every step:
p0 = np.array([1.0, 0.0])
c = np.linalg.solve(V, p0) # coordinates of p0 in the eigenbasis
print('P^50 p0 :', np.linalg.matrix_power(P, 50) @ p0)
print('sum c_i lam_i^50 v_i:', V @ (c * lam ** 50))
pi = np.array([1 / 3, 2 / 3])
errs = np.array([np.abs(np.linalg.matrix_power(P, k) @ p0 - pi).max()
for k in range(8)])
print('error ratios:', np.round(errs[1:] / errs[:-1], 4))P^50 p0 : [0.33333333 0.66666667]
sum c_i lam_i^50 v_i: [0.33333333 0.66666667]
error ratios: [0.25 0.25 0.25 0.25 0.25 0.25 0.25]
General Matrix Functions: The exact same eigenbasis recipe defines matrix inverses \mathbf{A}^{-1} = \mathbf{V}\boldsymbol{\Lambda}^{-1}\mathbf{V}^{-1} (when all \lambda_i \neq 0) and matrix exponentials e^{\mathbf{A}t} = \mathbf{V}e^{\boldsymbol{\Lambda}t}\mathbf{V}^{-1} for continuous-time differential equations \dot{\mathbf{x}} = \mathbf{A}\mathbf{x}.
Similarity & Invariants
Multiplicity & Diagonalizability
When Diagonalization Fails
Jordan Normal Form
Jordan Normal Form
k = 1 ||J^k|| = 1.609 k * 0.99^(k-1) = 1.000
k = 50 ||J^k|| = 30.568 k * 0.99^(k-1) = 30.556
k = 100 ||J^k|| = 36.977 k * 0.99^(k-1) = 36.973
k = 200 ||J^k|| = 27.067 k * 0.99^(k-1) = 27.067
k = 800 ||J^k|| = 0.260 k * 0.99^(k-1) = 0.260
Complex Spectra in Real Matrices
Complex Spectra in Code
Extracting the real and imaginary parts of the complex eigenvector transforms \mathbf{A} into the exact block \left(\begin{smallmatrix}2&-1\\1&2\end{smallmatrix}\right), while standard coordinates show non-uniform per-step norm ratios:
A = np.array([[1., 2.], [-1., 3.]])
lam, V = np.linalg.eig(A)
j = np.argmax(lam.imag) # the eigenvalue a + ib with b > 0
r, theta = np.abs(lam[j]), np.angle(lam[j])
u, v = V[:, j].real, V[:, j].imag
B = np.column_stack([v, u]) # basis (v, u) of the invariant plane
print(f'lambda = {lam[j]:.4f} r = {r:.4f} theta = {theta:.4f}')
print('B^-1 A B =\n', np.round(np.linalg.inv(B) @ A @ B, 4))
xs = [np.array([1., 0.])]
for _ in range(8):
xs.append(A @ xs[-1])
norms = np.linalg.norm(xs, axis=1)
print('norm ratios:', np.round(norms[1:] / norms[:-1], 2))
x20 = np.linalg.matrix_power(A, 20) @ np.array([1., 0.])
print(f'average rate ||A^20 x||^(1/20) = {np.linalg.norm(x20) ** (1 / 20):.3f}')Complex Spectra in Code
lambda = 2.0000+1.0000j r = 2.2361 theta = 0.4636
B^-1 A B =
[[ 2. -1.]
[ 1. 2.]]
norm ratios: [1.41 2.92 3.45 2.76 2.27 1.88 1.5 1.54]
average rate ||A^20 x||^(1/20) = 2.252
Why Per-Step Ratios Swing Between 1.4 and 3.5: The rotation–scaling is uniform only in the non-orthogonal basis (\mathbf{v}, \mathbf{u}); in standard coordinates, iterates spiral along tilted ellipses whose geometric average growth rate settles to \sqrt{5} \approx 2.236.
Real Jordan Form Synthesis
Symmetric Matrices
Symmetric Matrices
Quadratic Forms
Positive Definiteness in ML
X_full = np.array([[1., 0.], [1., 1.], [0., 1.], [2., 1.]]) # rank 2
X_dep = np.array([[1., 2.], [1., 2.], [0., 0.], [2., 4.]]) # col 2 = 2*col 1
for X, name in [(X_full, 'full column rank'), (X_dep, 'dependent columns')]:
eigvals = np.linalg.eigvalsh(X.T @ X).round(4)
eigvals[np.abs(eigvals) < 1e-9] = 0.0 # clean up tiny round-off / -0.0
print(f'{name}: eigenvalues of X^T X = {eigvals}')full column rank: eigenvalues of X^T X = [1.1459 7.8541]
dependent columns: eigenvalues of X^T X = [ 0. 30.]
Variational Characterization
High-Dimensional Statistics
n, d = 4000, 1000 # aspect ratio c = d / n = 1/4
X = np.random.randn(n, d) # pure noise: true covariance I
ev = np.linalg.eigvalsh(X.T @ X / n)
c = d / n
print(f'eigenvalues of C: min {ev.min():.3f}, max {ev.max():.3f}')
print(f'Marchenko-Pastur edges: {(1 - c ** 0.5) ** 2:.3f}, '
f'{(1 + c ** 0.5) ** 2:.3f}')eigenvalues of C: min 0.247, max 2.238
Marchenko-Pastur edges: 0.250, 2.250
Concept Check
Answers: 1. Roots of \lambda^2 - 8\lambda + 15 = (\lambda - 3)(\lambda - 5) = 0, so \lambda_1 = 5 and \lambda_2 = 3. 2. (i) \operatorname{tr}\mathbf{S} = 4 > 0 and \det\mathbf{S} = 3 > 0, so both real eigenvalues are positive; (ii) completing the square gives \mathbf{x}^\top\mathbf{S}\mathbf{x} = x_1^2 + x_2^2 + (x_1 + x_2)^2 > 0 for all \mathbf{x} \neq \mathbf{0}. 3. Centering 256 rows leaves rank at most n - 1 = 255, so \mathbf{C} has at least 512 - 255 = 257 zero eigenvalues and cannot be inverted without regularization.
Key Takeaways
| Concept | Mathematical Form | Key Property / Deep Learning Role |
|---|---|---|
| Eigenpair & Polynomial | \mathbf{A}\mathbf{v} = \lambda\mathbf{v}, \det(\mathbf{A} - \lambda\mathbf{I}) = 0 | Invariant directions scaled by \lambda; \operatorname{tr}\mathbf{A} = \sum_i \lambda_i and \det\mathbf{A} = \prod_i \lambda_i |
| Diagonalization & Powers | \mathbf{A} = \mathbf{V}\boldsymbol{\Lambda}\mathbf{V}^{-1}, \mathbf{A}^k\mathbf{x} = \sum_i c_i \lambda_i^k \mathbf{v}_i | Exists iff g(\lambda) = a(\lambda) for all \lambda; decouples k-step dynamics into scalar powers |
| Defective & Complex Cases | \mathbf{J}_2(\lambda)^k = \lambda^k\mathbf{I} + k\lambda^{k-1}\mathbf{N}, \lambda = r e^{\pm i\theta} | Missing eigenvectors cause k\lambda^{k-1} transient growth; complex pairs rotate and scale a 2D plane |
| Spectral Theorem | \mathbf{A} = \mathbf{A}^\top \implies \mathbf{A} = \mathbf{V}\boldsymbol{\Lambda}\mathbf{V}^\top | Every real symmetric matrix has real eigenvalues and an orthonormal eigenbasis (\mathbf{V}^{-1} = \mathbf{V}^\top) |
| Quadratic Form & Rayleigh | \mathbf{x}^\top\mathbf{A}\mathbf{x} = \sum_i \lambda_i y_i^2, R(\mathbf{x}) \in [\lambda_{\min}, \lambda_{\max}] | \mathbf{A} \succ 0 \iff all \lambda_i > 0; caps gradient descent step size at \eta < 2/\lambda_{\max} |
| Marchenko–Pastur Bulk | \lambda(\tfrac{1}{n}\mathbf{X}^\top\mathbf{X}) \in [(1-\sqrt{c})^2, (1+\sqrt{c})^2] | Pure-noise sample eigenvalues spread with c = d/n; only spikes above (1+\sqrt{c})^2 are signal |