Equations · Standard linear algebra (Beltrami 1873, Jordan 1874); Eckart and Young (1936) for low-rank approximation

The singular value decomposition (SVD), explained

Every matrix, of any shape, factors into a rotation, a scaling along the axes, and another rotation. The SVD also writes the matrix as a sum of rank-one pieces, ordered by importance; keeping the first kk gives the best rank-kk approximation. It underlies PCA, low-rank compression and LoRA's motivation.

A=UΣV⊤=∑i=1rσiuivi⊤A = U \Sigma V^\top = \sum_{i=1}^{r} \sigma_i \mathbf{u}_i \mathbf{v}_i^\top

Open in the decoder →

Term by term

  1. AA

    Any m×nm \times n matrix.

  2. U, VU, \ V

    Orthogonal matrices (U⊤U=IU^\top U = I, V⊤V=IV^\top V = I). Their columns ui\mathbf{u}_i and vi\mathbf{v}_i are the left and right singular vectors.

  3. Σ\Sigma

    A diagonal matrix of singular values. Here Σ\Sigma is a matrix, not a sum and not a covariance.

  4. σi\sigma_i

    The ii-th singular value: non-negative, sorted so σ1≥σ2≥…\sigma_1 \ge \sigma_2 \ge \ldots. Not a standard deviation. σi2\sigma_i^2 are the eigenvalues of A⊤AA^\top A.

  5. ∑i=1rσiuivi⊤\sum_{i=1}^{r} \sigma_i \mathbf{u}_i \mathbf{v}_i^\top

    The same matrix as a sum of rr rank-one outer products, where rr is the rank of AA. Truncating the sum at kk terms gives the closest rank-kk matrix in the Frobenius and spectral norms.

Shapes

A small worked example

A=(2211)A = \begin{pmatrix} 2 & 2 \\ 1 & 1 \end{pmatrix} has rank 1. Its SVD has σ1=10≈3.16\sigma_1 = \sqrt{10} \approx 3.16, σ2=0\sigma_2 = 0, u1=(2,1)/5\mathbf{u}_1 = (2, 1)/\sqrt{5}, v1=(1,1)/2\mathbf{v}_1 = (1, 1)/\sqrt{2}. Check: σ1u1v1⊤=1010(2211)=A\sigma_1 \mathbf{u}_1 \mathbf{v}_1^\top = \frac{\sqrt{10}}{\sqrt{10}} \begin{pmatrix} 2 & 2 \\ 1 & 1 \end{pmatrix} = A.

In code

import numpy as np

A = np.array([[2.0, 2.0], [1.0, 1.0]])
U, S, Vt = np.linalg.svd(A, full_matrices=False)   # S: singular values, sorted
k = 1
A_k = (U[:, :k] * S[:k]) @ Vt[:k]                  # best rank-k approximation

Every symbol in it

W∈Rm×n\mathbf{W} \in \mathbb{R}^{m \times n}Bold uppercase (matrix)x⊤y\mathbf{x}^\top \mathbf{y}TransposeΣ\SigmaSigma (capital)diag⁡(v)\operatorname{diag}(\mathbf{v})Diagσ(z)\sigma(z)Sigma (lowercase)xi,  Wq,  pθ,  dmodelx_i,\; W_q,\; p_\theta,\; d_{\text{model}}Subscript (index or label)∑i=1Nxi\sum_{i=1}^{N} x_iSummationx∈Rd\mathbf{x} \in \mathbb{R}^{d}Bold lowercase (vector)

Other equations