Singular Value Decomposition and Low-Rank Approximation

Dive into Deep Learning · §33.5

Singular Value Decomposition and Low-Rank Approximation
two orthonormal bases · four subspaces · Eckart–Young & PCA · pseudoinverse & conditioning · LoRA & Muon

Why One Basis Is Not Enough for Deep Learning

Motivation

  • Rectangular Layers & Data Tables: Weight matrices \mathbf{W} \in \mathbb{R}^{m \times n} and data tables \mathbf{X} \in \mathbb{R}^{n \times d} are not square, so eigenvalues do not exist.
  • Two Orthonormal Bases (\mathbf{V} and \mathbf{U}): Pairing an input basis \mathbf{V} with an output basis \mathbf{U} turns every matrix into non-negative stretches \mathbf{A}\mathbf{v}_i = \sigma_i\mathbf{u}_i.
  • Low-Rank Compression: Keeping k = 20 rank-1 pieces of a 400 \times 500 cat photo uses 9\% storage at 8\% relative error.

The SVD: Rotate, Stretch Along Axes, Rotate

The Factorization

  • Theorem (\mathbf{A} = \mathbf{U}\boldsymbol{\Sigma}\mathbf{V}^\top): Every real m \times n matrix factors into orthogonal \mathbf{U} \in \mathbb{R}^{m \times m} (left singular vectors \mathbf{u}_i), diagonal \boldsymbol{\Sigma} \in \mathbb{R}^{m \times n} with \sigma_1 \ge \sigma_2 \ge \cdots \ge 0, and orthogonal \mathbf{V} \in \mathbb{R}^{n \times n} (right singular vectors \mathbf{v}_i).
  • Directional Action (\mathbf{A}\mathbf{v}_i = \sigma_i\mathbf{u}_i): Reading \mathbf{U}\boldsymbol{\Sigma}\mathbf{V}^\top\mathbf{x} right to left rotates the input frame \{\mathbf{v}_i\} onto the coordinate axes (\mathbf{V}^\top), stretches axis i by \sigma_i (\boldsymbol{\Sigma}), and rotates onto the output frame \{\mathbf{u}_i\} (\mathbf{U}).

Full, Thin, Compact, and Dyadic Forms of the SVD

SVD Representations

  • Full vs. Thin SVD: Full SVD keeps square orthogonal \mathbf{U}_{m\times m}, \mathbf{V}_{n\times n}; thin SVD keeps p = \min(m, n) columns (full_matrices=False).
  • Compact SVD (r = \operatorname{rank}\mathbf{A}): Keeps only positive stretches \sigma_1 \ge \cdots \ge \sigma_r > 0.
  • Dyadic Sum: \mathbf{A} = \sum_{i=1}^r \sigma_i\mathbf{u}_i\mathbf{v}_i^\top sorts rank-1 outer products from heaviest to lightest.

Existence Proof: Spectral Theorem on AᵀA

Why the SVD Always Exists

  • 1. Diagonalize PSD Gram Matrix \mathbf{A}^\top\mathbf{A}: Orthonormal eigenvectors \mathbf{v}_1, \ldots, \mathbf{v}_n have eigenvalues \lambda_1 \ge \cdots \ge \lambda_n \ge 0.
  • 2. Push Forward (\sigma_i = \sqrt{\lambda_i}): For i \le r, set \mathbf{u}_i = \mathbf{A}\mathbf{v}_i/\sigma_i; for i > r, \|\mathbf{A}\mathbf{v}_i\|^2 = 0 \implies \mathbf{A}\mathbf{v}_i = \mathbf{0}.
  • 3. Automatic Orthonormality: \mathbf{u}_i^\top\mathbf{u}_j = \frac{\mathbf{v}_i^\top\mathbf{A}^\top\mathbf{A}\mathbf{v}_j}{\sigma_i\sigma_j} = \delta_{ij}.

Worked Example: SVD of the Defective Shear T

By-Hand & Numerical SVD

  • Golden-Ratio Stretches: For \mathbf{T} = \left(\begin{smallmatrix}1&1\\0&1\end{smallmatrix}\right), \mathbf{T}^\top\mathbf{T} = \left(\begin{smallmatrix}1&1\\1&2\end{smallmatrix}\right) has \operatorname{tr} = 3, \det = 1, and eigenvalues \lambda = (3 \pm \sqrt{5})/2 = \varphi^2, \varphi^{-2} where \varphi = (1+\sqrt{5})/2 \approx 1.618, giving \sigma_1 = \varphi \approx 1.618 and \sigma_2 = 1/\varphi \approx 0.618.
  • Input and Output Angles: Solving (\mathbf{T}^\top\mathbf{T} - \varphi^2\mathbf{I})\mathbf{v}_1 = \mathbf{0} yields \mathbf{v}_1 \propto (1, \varphi) at 58.3^\circ and \mathbf{u}_1 = \mathbf{T}\mathbf{v}_1/\varphi \propto (\varphi, 1) at 31.7^\circ, so \mathbf{T} = \mathbf{R}_{31.7^\circ}\operatorname{diag}(\varphi, 1/\varphi)\mathbf{R}_{58.3^\circ}^\top:

Worked Example: SVD of the Defective Shear T (cont.)

By-Hand & Numerical SVD

A = np.array([[1., 1.], [0., 1.]])
U, s, Vt = np.linalg.svd(A)
if U[0, 0] < 0:                         # joint sign choice: u_1 in the first quadrant
    U[:, 0], Vt[0] = -U[:, 0], -Vt[0]
if np.linalg.det(U) < 0:                # joint sign choice: U a rotation (then so is V)
    U[:, 1], Vt[1] = -U[:, 1], -Vt[1]
phi = (1 + np.sqrt(5)) / 2
print('singular values', s.round(4), '  phi, 1/phi', np.array([phi, 1 / phi]).round(4))
print('U =', U.round(3).tolist(), '  Vt =', Vt.round(3).tolist())
print('angles of u_1, v_1 (degrees):', np.degrees(np.arctan2(U[1, 0], U[0, 0])).round(1),
      np.degrees(np.arctan2(Vt[0, 1], Vt[0, 0])).round(1))
print('A v_1 = sigma_1 u_1:', np.allclose(A @ Vt[0], s[0] * U[:, 0]),
      '  sigma_1 sigma_2 =', s.prod().round(6))
singular values [1.618 0.618]   phi, 1/phi [1.618 0.618]
U = [[0.851, -0.526], [0.526, 0.851]]   Vt = [[0.526, 0.851], [-0.851, 0.526]]
angles of u_1, v_1 (degrees): 31.7 58.3
A v_1 = sigma_1 u_1: True   sigma_1 sigma_2 = 1.0

Constructing a Rectangular SVD From AᵀA in Code

By-Hand & Numerical SVD

Carrying out the proof recipe on a 3 \times 2 matrix (\mathbf{A}^\top\mathbf{A} = \left(\begin{smallmatrix}10&6\\6&14\end{smallmatrix}\right), \lambda = 12 \pm \sqrt{40}) reproduces np.linalg.svd up to joint sign flips (\mathbf{u}_i, \mathbf{v}_i) \mapsto (-\mathbf{u}_i, -\mathbf{v}_i):

A = np.array([[3., 1.], [1., 3.], [0., 2.]])
lam, V = np.linalg.eigh(A.T @ A)
lam, V = lam[::-1], V[:, ::-1]                     # descending order
sigma = np.sqrt(lam)
U = A @ V / sigma                                   # u_i = A v_i / sigma_i
U_lib, s_lib, Vt_lib = np.linalg.svd(A, full_matrices=False)
print('sigma from eigh:', sigma.round(5), '  from svd:', s_lib.round(5))
print('U orthonormal:', np.allclose(U.T @ U, np.eye(2)), '  same U, V up to sign:',
      np.allclose(abs(U), abs(U_lib)), np.allclose(abs(V), abs(Vt_lib.T)))
print('rebuild error:', np.linalg.norm((U * sigma) @ V.T - A).round(12))
sigma from eigh: [4.28072 2.38232]   from svd: [4.28072 2.38232]
U orthonormal: True   same U, V up to sign: True True
rebuild error: 0.0

Why Libraries Use Golub–Kahan Bidiagonalization: Although \mathbf{A}^\top\mathbf{A} proves existence, forming \mathbf{A}^\top\mathbf{A} in floating point squares the condition number \kappa(\mathbf{A})^2 and wipes out small singular values. Production SVD solvers apply orthogonal transformations directly to \mathbf{A}.

The Four Fundamental Subspaces From the SVD

Subspace Geometry

  • Exact Rank (r = \#\{\sigma_i > 0\}): Orthogonal matrices preserve dimension, so \operatorname{rank}\mathbf{A} = \operatorname{rank}\boldsymbol{\Sigma} = r.
  • Orthonormal Bases for All Four Subspaces:
    • Row space \operatorname{col}(\mathbf{A}^\top) = \operatorname{span}\{\mathbf{v}_1, \ldots, \mathbf{v}_r\} \subseteq \mathbb{R}^n
    • Null space \ker(\mathbf{A}) = \operatorname{span}\{\mathbf{v}_{r+1}, \ldots, \mathbf{v}_n\} \subseteq \mathbb{R}^n
    • Column space \operatorname{col}(\mathbf{A}) = \operatorname{span}\{\mathbf{u}_1, \ldots, \mathbf{u}_r\} \subseteq \mathbb{R}^m
    • Left null space \ker(\mathbf{A}^\top) = \operatorname{span}\{\mathbf{u}_{r+1}, \ldots, \mathbf{u}_m\} \subseteq \mathbb{R}^m
  • Bijection on the Row Space: \mathbf{A} maps \mathbf{v}_i \mapsto \sigma_i\mathbf{u}_i (i \le r) one-to-one and crushes \ker\mathbf{A} to zero.

Numerical Rank and Floating-Point Thresholding

Subspace Geometry in Practice

  • Exact Zeros Are Unreliable: Rounding error perturbs singular values by up to \|\mathbf{E}\|_2 \sim \epsilon_{\text{mach}}\sigma_1 (Weyl’s inequality), so a mathematical zero usually comes out as a tiny number around 10^{-15}\sigma_1 and only sometimes as an exact 0.
  • Standard Rank Tolerance: np.linalg.matrix_rank counts singular values exceeding \text{tol} = \sigma_1 \max(m, n)\,\epsilon_{\text{mach}}:
A = np.random.standard_normal((4, 2)) @ np.random.standard_normal((2, 4))   # rank <= 2
s = np.linalg.svd(A, compute_uv=False)
tol = s[0] * max(A.shape) * np.finfo(float).eps
print('singular values:', np.array2string(s, formatter={'float_kind': '{:.1e}'.format}))
print(f'tolerance {tol:.1e};  exact zeros: {(s == 0).sum()};  '
      f'numerical rank: {np.linalg.matrix_rank(A)}')
singular values: [4.4e+00 2.2e+00 4.7e-17 0.0e+00]
tolerance 3.9e-15;  exact zeros: 1;  numerical rank: 2

Truncated SVD and the Eckart–Young Theorem

Best Low-Rank Approximation

  • Rank-k Truncated SVD: \mathbf{A}_k = \sum_{i=1}^k \sigma_i\mathbf{u}_i\mathbf{v}_i^\top stores k(m + n + 1) numbers instead of mn.
  • Eckart–Young–Mirsky Theorem: \mathbf{A}_k minimizes \|\mathbf{A} - \mathbf{B}\| over all \operatorname{rank}\mathbf{B} \le k in both spectral (\sigma_{k+1}) and Frobenius (\sqrt{\sum_{i>k}\sigma_i^2}) norms.
  • Uniqueness: Unique in Frobenius norm whenever \sigma_k > \sigma_{k+1}.

Proving Eckart–Young by Subspace Intersection

Proof of Eckart–Young

  • Dimension Count (\dim\mathcal{K} + \dim\mathcal{V} > n): Any competitor \mathbf{B} with \operatorname{rank}\mathbf{B} \le k has null space \mathcal{K} = \ker\mathbf{B} of dimension at least n - k, while \mathcal{V} = \operatorname{span}\{\mathbf{v}_1, \ldots, \mathbf{v}_{k+1}\} has dimension k + 1.
  • Nontrivial Intersection: Since (n - k) + (k + 1) = n + 1 > n, \mathcal{K} \cap \mathcal{V} contains a unit vector \mathbf{x} = \sum_{i=1}^{k+1} c_i\mathbf{v}_i (\sum c_i^2 = 1) where \mathbf{B}\mathbf{x} = \mathbf{0}.
  • Lower Bound: On this \mathbf{x}, \mathbf{A} still stretches by at least \sigma_{k+1}: \|\mathbf{A} - \mathbf{B}\|_2^2 \ge \|\mathbf{A}\mathbf{x}\|^2 = \sum_{i=1}^{k+1} c_i^2\sigma_i^2 \ge \sigma_{k+1}^2

Weyl’s Inequality and the Frobenius Norm Proof

Perturbation & Frobenius Bound

  • Weyl’s Lemma: \sigma_{i+j-1}(\mathbf{X} + \mathbf{Y}) \le \sigma_i(\mathbf{X}) + \sigma_j(\mathbf{Y}) by comparing \mathbf{X} + \mathbf{Y} against rank-(i+j-2) truncation \mathbf{X}_{i-1} + \mathbf{Y}_{j-1}.
  • 1-Lipschitz Stability (j = 1): |\sigma_i(\mathbf{A} + \mathbf{E}) - \sigma_i(\mathbf{A})| \le \|\mathbf{E}\|_2.
  • Frobenius Proof (j = k + 1): \sigma_i(\mathbf{A} - \mathbf{B}) \ge \sigma_{k+i}(\mathbf{A}) \implies \|\mathbf{A} - \mathbf{B}\|_F^2 \ge \sum_{i>k}\sigma_i^2.

Eckart–Young on a 400×500 Photograph

Low-Rank Compression

  • Power-Law Decay (\sigma_i \propto i^{-1.1}): Because natural images have rapidly decaying singular values, k = 20 dyads capture 99.4\% of the Frobenius energy (8\% relative error) using only 9\% of the parameters, beating projection onto the 20 largest image columns (31\% error) by nearly 4\times.

Energy Ratio, Centering, and SVD Denoising

Choosing the Rank k

  • Frobenius Energy Ratio: The fraction of total squared energy retained at rank k directly determines the relative Frobenius error: \text{Energy}(k) = \frac{\sum_{i \le k} \sigma_i^2}{\sum_{i=1}^r \sigma_i^2} = 1 - \frac{\|\mathbf{A} - \mathbf{A}_k\|_F^2}{\|\mathbf{A}\|_F^2}

  • Mean Dominance & Gavish–Donoho Denoising: On the uncentered photo, \sigma_1^2 holds 89\% of the energy simply from average brightness; under additive noise \mathbf{A} = \mathbf{B} + \mathbf{N} (\sigma_{\text{noise}}), optimal hard thresholding discards singular values below \tfrac{4}{\sqrt{3}}\sqrt{n}\,\sigma_{\text{noise}} \approx 2.309\sqrt{n}\,\sigma_{\text{noise}}.

400 x 500 = 200000 numbers;  slope of log sigma_i on log i: -1.11
energy kept at rank 1: 0.886, at rank 4: 0.955
k= 1: ||A-A_k||_2=  9234  sigma_2=  9234  rel. err 0.337  stores 0.5%
k= 5: ||A-A_k||_2=  4048  sigma_6=  4048  rel. err 0.191  stores 2.3%
k=20: ||A-A_k||_2=   874  sigma_21=   874  rel. err 0.080  stores 9.0%
k=50: ||A-A_k||_2=   342  sigma_51=   342  rel. err 0.045  stores 22.5%
projection onto the 20 largest columns: rel. err 0.310

Energy Ratio, Centering, and SVD Denoising (cont.)

Choosing the Rank k

img = d2l.plt.imread('../img/cat1.jpg') @ np.array([0.299, 0.587, 0.114])  # 400 x 500
U, s, Vt = np.linalg.svd(img, full_matrices=False)
m, n = img.shape
fro = np.linalg.norm(img)
energy = np.cumsum(s**2) / (s**2).sum()                        # energy kept at each rank
slope = np.polyfit(np.log(np.arange(1, 101)), np.log(s[:100]), 1)[0]
print(f'{m} x {n} = {m * n} numbers;  slope of log sigma_i on log i: {slope:.2f}')
print(f'energy kept at rank 1: {energy[0]:.3f}, at rank 4: {energy[3]:.3f}')
for k in [1, 5, 20, 50]:
    A_k = np.einsum('i,mi,in->mn', s[:k], U[:, :k], Vt[:k])    # first k dyads
    print(f'k={k:2d}: ||A-A_k||_2={np.linalg.norm(img - A_k, 2):6.0f}  '
          f'sigma_{k + 1}={s[k]:6.0f}  rel. err {np.linalg.norm(img - A_k) / fro:.3f}  '
          f'stores {k * (m + n + 1) / (m * n):.1%}')
cols = np.argsort(-np.linalg.norm(img, axis=0))[:20]           # 20 largest columns
C = img[:, cols]
proj = C @ np.linalg.pinv(C) @ img
print(f'projection onto the 20 largest columns: rel. err {np.linalg.norm(img - proj) / fro:.3f}')

Principal Component Analysis via Centered SVD

Dimensionality Reduction

  • Center First (\tilde{\mathbf{X}} = \mathbf{X} - \mathbf{1}\bar{\mathbf{x}}^\top): The optimal k-dimensional affine plane always passes through the sample mean \bar{\mathbf{x}}, with covariance \mathbf{C} = \tfrac{1}{n}\tilde{\mathbf{X}}^\top\tilde{\mathbf{X}} = \tfrac{1}{n}\mathbf{V}\boldsymbol{\Sigma}^\top\boldsymbol{\Sigma}\mathbf{V}^\top.
  • Maximum Variance = Minimum Error: By Rayleigh and Eckart–Young, the top right singular vectors \mathbf{v}_1, \ldots, \mathbf{v}_k of \tilde{\mathbf{X}} simultaneously maximize projected variance (\sigma_i^2/n) and minimize reconstruction error: \tilde{\mathbf{X}}\mathbf{V}_k\mathbf{V}_k^\top = \mathbf{U}_k\boldsymbol{\Sigma}_k\mathbf{V}_k^\top = \tilde{\mathbf{X}}_k

PCA Variance and Reconstruction Error in Code

PCA in Practice

On a 300-point cloud rotated by 36^\circ with population standard deviations 3.0 and 0.8, the SVD of the centered data recovers the principal axis and matches the mean squared rank-1 error to \sigma_2^2/n:

theta = np.pi / 5
rot = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]])
X = np.random.standard_normal((300, 2)) * np.array([3.0, 0.8]) @ rot.T   # the cloud
Xc = X - X.mean(0)
U, s, Vt = np.linalg.svd(Xc, full_matrices=False)
X1 = np.outer(U[:, 0] * s[0], Vt[0])                                    # rank-1 reconstruction
print('explained-variance ratio:', (s**2 / (s**2).sum()).round(3), ' (population 0.934, 0.066)')
print('angle of v_1 to the long axis:',
      np.degrees(np.arccos(abs(Vt[0] @ rot[:, 0]))).round(1), 'degrees')
print('mean squared rank-1 error:', (((Xc - X1)**2).sum() / 300).round(4),
      '  sigma_2^2 / n:', (s[1]**2 / 300).round(4))
explained-variance ratio: [0.923 0.077]  (population 0.934, 0.066)
angle of v_1 to the long axis: 0.6 degrees
mean squared rank-1 error: 0.7111   sigma_2^2 / n: 0.7111

What Happens If You Forget to Center? Without subtracting X.mean(0), \mathbf{v}_1 points from the origin toward the cloud’s center of mass \bar{\mathbf{x}} rather than along its axis of greatest spread.

The Moore–Penrose Pseudoinverse A⁺

Solving Linear Systems

  • Inverting Nonzero Stretches: For any \mathbf{A} = \mathbf{U}\boldsymbol{\Sigma}\mathbf{V}^\top \in \mathbb{R}^{m \times n}, the Moore–Penrose pseudoinverse \mathbf{A}^+ \in \mathbb{R}^{n \times m} is: \mathbf{A}^+ = \mathbf{V}\boldsymbol{\Sigma}^+\mathbf{U}^\top where \boldsymbol{\Sigma}^+_{ii} = 1/\sigma_i for \sigma_i > 0 and 0 otherwise.
  • Minimum-Norm Least Squares (\hat{\mathbf{x}} = \mathbf{A}^+\mathbf{b}): In singular coordinates \mathbf{y} = \mathbf{V}^\top\mathbf{x} and \mathbf{c} = \mathbf{U}^\top\mathbf{b}, \|\mathbf{A}\mathbf{x} - \mathbf{b}\|^2 = \sum_{i \le r}(\sigma_i y_i - c_i)^2 + \sum_{i > r} c_i^2.
  • Disjoint Roles: Setting y_i = c_i/\sigma_i (i \le r) minimizes the residual, while setting null-space coordinates y_i = 0 (i > r) minimizes \|\mathbf{x}\| = \|\mathbf{y}\|.

Ridge Regression as a Spectral Filter

Regularized Least Squares

  • Why Small Singular Values Are Dangerous: In \mathbf{A}^+\mathbf{b} = \sum_{i \le r} \frac{\mathbf{u}_i^\top\mathbf{b}}{\sigma_i}\mathbf{v}_i, dividing by a tiny \sigma_i amplifies measurement noise along \mathbf{u}_i by 1/\sigma_i.
  • Ridge vs. Truncated SVD Filter Factors: Ridge regression \min_{\mathbf{x}} \|\mathbf{A}\mathbf{x} - \mathbf{b}\|^2 + \lambda\|\mathbf{x}\|^2 (weight decay) smoothly damps directions with \sigma_i^2 \ll \lambda instead of cutting them off sharply: \mathbf{x}_\lambda = (\mathbf{A}^\top\mathbf{A} + \lambda\mathbf{I})^{-1}\mathbf{A}^\top\mathbf{b} = \sum_{i=1}^r \underbrace{\frac{\sigma_i^2}{\sigma_i^2 + \lambda}}_{\text{ridge filter}} \frac{\mathbf{u}_i^\top\mathbf{b}}{\sigma_i}\,\mathbf{v}_i

Ridge Regression as a Spectral Filter (cont.)

Regularized Least Squares

A = np.array([[1., 1.], [1., 2.], [1., 3.], [1., 4.]])     # 4 equations, 2 unknowns
b = np.array([6., 5., 7., 10.])
x_pinv = np.linalg.pinv(A) @ b
x_lstsq = np.linalg.lstsq(A, b, rcond=None)[0]
print('overdetermined: pinv', x_pinv.round(4), ' lstsq', x_lstsq.round(4),
      ' residual', np.linalg.norm(A @ x_pinv - b).round(4))
A1 = np.array([[1., 1.]])                                  # 1 equation: x1 + x2 = 2
x1 = np.linalg.pinv(A1) @ np.array([2.])
print('underdetermined: pinv gives', x1.round(4), ' norm', np.linalg.norm(x1).round(4))
overdetermined: pinv [3.5 1.4]  lstsq [3.5 1.4]  residual 2.0494
underdetermined: pinv gives [1. 1.]  norm 1.4142

The Condition Number κ(A) = σ₁ / σᵣ

Sensitivity & Conditioning

  • Ratio of Extreme Stretches: \kappa(\mathbf{A}) = \sigma_1/\sigma_r \ge 1 (\kappa = 1 for orthogonal \mathbf{Q}; \kappa = \infty for singular matrices).
  • Relative Error Amplification: Perturbing \mathbf{A}\mathbf{x} = \mathbf{b} by \delta\mathbf{b} amplifies relative solution error by at most \kappa(\mathbf{A}): \frac{\|\delta\mathbf{x}\|}{\|\mathbf{x}\|} \le \kappa(\mathbf{A})\frac{\|\delta\mathbf{b}\|}{\|\mathbf{b}\|}.
  • Gram Squaring: \kappa(\mathbf{A}^\top\mathbf{A}) = (\sigma_1/\sigma_r)^2 = \kappa(\mathbf{A})^2.

Condition Number Amplification & Narrow Valleys

Conditioning in Code & Optimization

K = np.array([[1., 1.], [1., 1.0001]])
b = np.array([2., 2.0001])
x = np.linalg.solve(K, b)
x2 = np.linalg.solve(K, b + np.array([0., 1e-4]))
print('x =', x.round(4), '  after changing b_2 by 1e-4:', x2.round(4) + 0.)
kappa = np.linalg.cond(K)
print(f'kappa(K) = {kappa:.0f};  bound {kappa * 1e-4 / np.linalg.norm(b):.2f};  '
      f'realized {np.linalg.norm(x2 - x) / np.linalg.norm(x):.2f}')
A = np.array([[1., 1.], [1., 2.], [1., 3.], [1., 4.]])
print(f'kappa(A) = {np.linalg.cond(A):.3f};  kappa(A^T A) = {np.linalg.cond(A.T @ A):.2f};  '
      f'kappa(A)^2 = {np.linalg.cond(A)**2:.2f}')
x = [1. 1.]   after changing b_2 by 1e-4: [0. 2.]
kappa(K) = 40002;  bound 1.41;  realized 1.00
kappa(A) = 7.469;  kappa(A^T A) = 55.78;  kappa(A)^2 = 55.78

  • Zig-Zagging in Gradient Descent: On \tfrac{1}{2}\|\mathbf{A}\mathbf{x} - \mathbf{b}\|^2, level sets have axis ratio \kappa(\mathbf{A}) while the Hessian \mathbf{H} = \mathbf{A}^\top\mathbf{A} has condition number \kappa(\mathbf{A})^2, causing gradient descent to bounce across steep valley walls.

LoRA: Low-Rank Adaptation of Pretrained Weights

SVD in Modern Deep Learning

  • Parallel Rank-k Bypass: LoRA freezes a pretrained weight \mathbf{W} \in \mathbb{R}^{m \times n} and learns a rank-k update \Delta\mathbf{W} = \mathbf{B}\mathbf{A} (\mathbf{B} \in \mathbb{R}^{m \times k}, \mathbf{A} \in \mathbb{R}^{k \times n}): \mathbf{h} = \mathbf{W}\mathbf{x} + \mathbf{B}\mathbf{A}\mathbf{x}
  • 256\times Parameter Compression: For a 4096 \times 4096 Transformer layer (16.8\text{M} weights), rank k = 8 trains only k(m+n) = 65{,}536 parameters (0.39\%) and merges into \mathbf{W} with zero inference overhead.
  • What Eckart–Young Says: Any full update \Delta\mathbf{W}_{\text{full}} can be matched within \sigma_{k+1}(\Delta\mathbf{W}_{\text{full}}), and LoRA succeeds because task updates have fast-decaying spectra.

Polar Decomposition and Muon’s Newton–Schulz Loop

Orthogonalized Matrix Updates

  • Polar Factor (\mathbf{Q} = \mathbf{U}\mathbf{V}^\top): Closest orthogonal matrix (\sigma_i \to 1), used by Muon to update all active directions at unit scale.
  • Matrix-Multiply Newton–Schulz Loop: Iterating \mathbf{X}_{t+1} = \tfrac{1}{2}(3\mathbf{X}_t - \mathbf{X}_t\mathbf{X}_t^\top\mathbf{X}_t) from \mathbf{M}/\|\mathbf{M}\|_F applies p(\sigma) = \tfrac{1}{2}(3\sigma - \sigma^3) \to 1.

Polar Decomposition and Muon’s Newton–Schulz Loop (cont.)

Orthogonalized Matrix Updates

M = np.random.standard_normal((6, 4))                # a stand-in momentum matrix
X = M / np.linalg.norm(M)                            # Frobenius normalization: sigma in (0, 1]
s_min = np.linalg.svd(X, compute_uv=False)[-1]
for k in range(1, 41):
    X = 1.5 * X - 0.5 * X @ X.T @ X                  # p(sigma) = (3 sigma - sigma^3) / 2
    if np.abs(np.linalg.svd(X, compute_uv=False) - 1).max() < 1e-6:
        break
U, s, Vt = np.linalg.svd(M, full_matrices=False)
print(f'smallest scaled sigma {s_min:.3f};  predicted steps '
      f'{np.log(1 / s_min) / np.log(1.5) + 4:.1f}')
print(f'steps until max|sigma_i - 1| < 1e-6: {k};  distance to U V^T: '
      f'{np.linalg.norm(X - U @ Vt):.1e}')
smallest scaled sigma 0.146;  predicted steps 8.7
steps until max|sigma_i - 1| < 1e-6: 9;  distance to U V^T: 7.3e-11

Spectral Normalization & Measuring Decay

Controlling and Auditing Spectra

  • Lipschitz Control via \sigma_1 = \|\mathbf{W}\|_2: Because \|\mathbf{W}\mathbf{x} - \mathbf{W}\mathbf{x}'\| \le \sigma_1\|\mathbf{x} - \mathbf{x}'\|, spectral normalization divides \mathbf{W} by an estimate of \sigma_1 tracked via 1 step of alternating power iteration (\mathbf{u} \leftarrow \mathbf{W}\mathbf{v}, \mathbf{v} \leftarrow \mathbf{W}^\top\mathbf{u}) per update.
  • Low Rank Must Be Measured, Not Assumed: Comparing a 400 \times 500 Gaussian noise matrix against our centered cat photograph shows why low-rank compression requires spectral decay:
G = np.random.standard_normal(img.shape)                       # no structure
for name, W in [('Gaussian', G), ('photograph', img - img.mean())]:
    s = np.linalg.svd(W, compute_uv=False)
    r95 = int(np.searchsorted(np.cumsum(s**2) / (s**2).sum(), 0.95)) + 1
    print(f'{name:10s}: sigma from {s[0]:.3g} to {s[-1]:.2g};  95% energy at rank {r95:3d};  '
          f'adapter {r95 * (m + n) / (m * n):.1%} of W')
Gaussian  : sigma from 42.2 to 2.5;  95% energy at rank 269;  adapter 121.0% of W
photograph: sigma from 2.65e+04 to 2.4;  95% energy at rank   8;  adapter 3.6% of W

Concept Check: SVD, Eckart–Young & Conditioning

Concept Check

  1. Singular Values vs. Eigenvalues: For \mathbf{A} = \left(\begin{smallmatrix}1&2\\-1&3\end{smallmatrix}\right) with eigenvalues 2 \pm i (|\lambda| = \sqrt{5}), are its singular values equal to \sqrt{5}? How do \sigma_1, \sigma_2 relate to \det\mathbf{A} = 5?
  2. Condition Number of the Shear: The shear \mathbf{T} = \left(\begin{smallmatrix}1&1\\0&1\end{smallmatrix}\right) has singular values \sigma_1 = \varphi and \sigma_2 = 1/\varphi (\varphi \approx 1.618). What are \kappa(\mathbf{T}) and \kappa(\mathbf{T}^\top\mathbf{T})?
  3. Underdetermined Pseudoinverse: What solution \hat{\mathbf{x}} = \mathbf{A}^+\mathbf{b} does the pseudoinverse return for the single equation x_1 + x_2 = 2, and why?

Answers: 1. No: \mathbf{A}^\top\mathbf{A} = \left(\begin{smallmatrix}2&-1\\-1&13\end{smallmatrix}\right) has eigenvalues \sigma_{1,2}^2 = (15 \pm 5\sqrt{5})/2, giving \sigma_1 \approx 3.618 and \sigma_2 \approx 1.382; their product is \sigma_1\sigma_2 = 5 = |\det\mathbf{A}| = |\lambda_1\lambda_2|. 2. \kappa(\mathbf{T}) = \sigma_1/\sigma_2 = \varphi / (1/\varphi) = \varphi^2 \approx 2.618, and forming the Gram matrix squares it to \kappa(\mathbf{T}^\top\mathbf{T}) = \varphi^4 \approx 6.854. 3. \hat{\mathbf{x}} = (1, 1), the unique point on the line x_1 + x_2 = 2 closest to the origin (zero component along the null-space vector (1, -1)).

Summary: Singular Value Decomposition

Key Takeaways

Concept / Tool Mathematical Expression Core Property & Deep Learning Role
SVD & Dyadic Sum \mathbf{A} = \mathbf{U}\boldsymbol{\Sigma}\mathbf{V}^\top = \sum_{i=1}^r \sigma_i\mathbf{u}_i\mathbf{v}_i^\top Exists for any m \times n matrix; \mathbf{A}\mathbf{v}_i = \sigma_i\mathbf{u}_i with \sigma_i = \sqrt{\lambda_i(\mathbf{A}^\top\mathbf{A})}
Four Subspaces & Norms r = \#\{\sigma_i > 0\}, \|\mathbf{A}\|_2 = \sigma_1, \|\mathbf{A}\|_F^2 = \sum \sigma_i^2 \mathbf{v}_{1..r} span row space, \mathbf{v}_{r+1..n} null space, \mathbf{u}_{1..r} col space, \mathbf{u}_{r+1..m} left null space
Eckart–Young & PCA \|\mathbf{A} - \mathbf{A}_k\|_2 = \sigma_{k+1}, \|\mathbf{A} - \mathbf{A}_k\|_F^2 = \sum_{i>k} \sigma_i^2 Truncated SVD \mathbf{A}_k is optimal rank-k approximation; on centered data \tilde{\mathbf{X}}_k gives PCA
Pseudoinverse & Ridge \mathbf{A}^+ = \mathbf{V}\boldsymbol{\Sigma}^+\mathbf{U}^\top, filter \frac{\sigma_i^2}{\sigma_i^2 + \lambda} \hat{\mathbf{x}} = \mathbf{A}^+\mathbf{b} is minimum-norm least-squares fit; ridge damps small-\sigma_i noise
Condition Number \kappa(\mathbf{A}) \kappa(\mathbf{A}) = \sigma_1/\sigma_r, \frac{\|\delta\mathbf{x}\|}{\|\mathbf{x}\|} \le \kappa\frac{\|\delta\mathbf{b}\|}{\|\mathbf{b}\|} Bounds error amplification and valley elongation; \kappa(\mathbf{A}^\top\mathbf{A}) = \kappa(\mathbf{A})^2
LoRA, Muon & Lipschitz \Delta\mathbf{W} = \mathbf{B}\mathbf{A}, \mathbf{Q} = \mathbf{U}\mathbf{V}^\top, \mathbf{W}/\sigma_1 LoRA compresses adapters; Newton–Schulz computes \mathbf{U}\mathbf{V}^\top for Muon; \sigma_1 bounds layer stretch