Math Fundamentals · lesson 13/15
Singular Value Decomposition (SVD)
The singular value decomposition factors any matrix into two rotations and a scaling. It tells you which directions a matrix stretches, by how much, and it gives the best low-rank approximation of that matrix for free. Compression, PCA, and LoRA all rest on it.
The idea
Every real matrix can be written
where is with orthonormal columns (left singular vectors), is with orthonormal columns (right singular vectors), and is with non-negative entries on the diagonal.
The reading: rotates the input into a basis where the action of is axis-aligned, scales along those axes, and rotates back out. Three consequences:
- Rank equals the number of nonzero singular values.
- Energy along component is , and the fraction retained by the first components is .
- Eckart–Young — the best rank- approximation in both the Frobenius and spectral norms is , made by truncating the decomposition. The Frobenius error is .
LoRA applies exactly this idea to a weight update: it assumes is approximately low rank and learns two thin factors instead of the full matrix.
Worked example
Take the symmetric matrix . Its singular values are and , with singular directions and . Expanding term by term:
The energy split is and , totaling 20, so the rank-1 term captures of the energy. The best rank-1 approximation is the first term, with Frobenius error . A rank-1 matrix cannot represent a general matrix, so the missing 20% is exactly the information the second direction carried.
In code
import numpy as np
A = np.array([[3.0, 1.0], [1.0, 3.0]])
U, s, Vt = np.linalg.svd(A)
print(s) # [4. 2.]
print(U @ np.diag(s) @ Vt) # [[3. 1.] [1. 3.]] reconstruction
A1 = s[0] * np.outer(U[:, 0], Vt[0])
print(np.linalg.norm(A - A1)) # 2.0, best rank-1 Frobenius errornp.linalg.svd returns rather than , and the singular values as a 1-D array in descending order.
Check yourself
- What does a singular value of zero imply about the matrix, and about solving ?
- State the Eckart–Young result in your own words.
- Why does truncating the smallest singular values compress an image or a weight matrix with limited loss?
Key takeaways
- SVD factors any matrix into orthogonal directions and non-negative scales.
- Rank is the count of nonzero singular values; energy is the sum of their squares.
- Truncated SVD is the provably best low-rank approximation, which is why it powers compression, PCA, and low-rank adapters.