PigeonColumba compressa

Lesson 9 of 10

Low-rank factorization with the SVD

Any matrix W (m x n) can be written as U diag(S) V^T with singular values S sorted from large to small. Keeping only the first r gives the best rank-r approximation in squared error (the Eckart-Young theorem), and the error is exactly the energy you dropped:

||W - W_r||_F = sqrt(S[r]^2 + S[r+1]^2 + ...)

Store it as two thin matrices A = U_r * sqrt(S_r) (m x r) and B = sqrt(S_r) * V_r^T (r x n): m*r + r*n numbers instead of m*n. It only saves space when r < m*n / (m + n).

Implement factorize(W, r) returning (A, B) with A @ B the best rank-r approximation.

Your code

Where this is used