Module 8: SVD
Now that you understand the structure of SVD, let's use it as a diagnostic tool. The singular values reveal everything important about a matrix.
Given A=UΣVT:
A applies the transformation by: rotate input via Vᵀ, stretch by Σ, rotate output by U. The singular vectors tell you the directions of maximum and minimum stretch.
The rank of A equals the number of nonzero singular values. A rank-1 matrix has σ₂ = 0 — the transformation collapses to a line. Rank-2 (full rank) has both σ₁, σ₂ > 0.
The condition number κ(A)=σ1/σ2 measures how "near-singular" a matrix is. If κ is large, small errors in b can cause large errors in the solution of Ax = b.
Edit the matrix. The dashed circle shows the unit circle (all inputs of length 1). The green ellipse shows where those inputs map to. The blue and pink arrows are the singular value directions. Make σ₂ near zero to collapse the ellipse to a line.
import numpy as np
A = np.array([[2., 1.], [0., 1.5]])
U, s, Vh = np.linalg.svd(A)
# Pseudoinverse: V @ Σ⁺ @ Uᵀ
S_inv = np.diag(1.0 / s)
A_pinv = Vh.T @ S_inv @ U.T
# Same as:
print(np.allclose(A_pinv, np.linalg.pinv(A))) # TrueSingular values:
σ₁ = 2.38 σ₂ = 1.26
Condition number σ₁/σ₂ = 1.89· · rank = 2
The dashed circle = inputs. The green ellipse = where A maps the unit circle. Its semi-axes are σ₁ and σ₂.