Skip to content

Low-rank approximation

Rebuild a picture from a few rank-one pieces, keep the largest ones for the best approximation, and count when it saves space.

Helps to know first
This topic

First, the picture

How many simple pieces does a picture need? Watch a photo rebuilt from 1, 2, 4, 8, 16 and 32 of them.

A photo from a few pieces

A picture is a matrix: keep only its largest singular pieces.

A 128 × 128 picture made of numbers, one for each pixel: 16 384 of them.

pieces k
1
numbers stored
257 / 16384
energy kept
97.80 %
0.00 / 10.80 s
Describe this picture

A 128×128128\times128 greyscale picture made in code: a sky that fades from top to bottom, a bright disc, a diagonal edge, and grainy textured ground below it. It is shown rebuilt from k=1k=1, 2, 4, 8, 16 and 32 pieces, 1.5 s each, with kk written in its corner. At k=1k=1 it is a soft plaid, horizontal bands times vertical bands: every row is a multiple of one row. Each step adds edges, then the disc’s outline, then the grain. Beside it (below it on a phone), a bar chart of the picture’s first 64 singular values on a log scale, largest first, with the kept bars lit. Readouts give kk, the numbers stored, 257k257k, against the picture’s own 16 384, and the share of the energy kept. One control after the clip: a slider for kk from 1 to 128.

A picture is a matrix

A greyscale picture is a table of brightness values, one per pixel, so it is a matrix. The picture at the top is 128×128128\times128: 16 384 numbers. By The singular value decomposition, it is a sum of rank-one pieces,

A=σ1u1v1⊤+σ2u2v2⊤+⋯ ,\mathbf{A}=\sigma_1\mathbf{u}_1\mathbf{v}_1^\top+\sigma_2\mathbf{u}_2\mathbf{v}_2^\top+\cdots,

with the singular values in decreasing order. Each piece uv⊤\mathbf{u}\mathbf{v}^\top is a column times a row. Every row of it is a multiple of the same row v⊤\mathbf{v}^\top, and every column a multiple of the same column u\mathbf{u}. As a picture, one piece is a plaid: horizontal bands times vertical bands. That is why the first frame of the clip looks like a plaid, not blurred in the usual way.

Watch out

A low-rank picture is not a low-resolution picture, and it does not keep the brightest pixels. It keeps every pixel, built from a few whole patterns. The first pieces carry the broad shapes, and the later ones add finer and finer detail.

Keep the largest pieces

Keep only the first kk pieces:

Ak=σ1u1v1⊤+⋯+σkukvk⊤.\mathbf{A}_k=\sigma_1\mathbf{u}_1\mathbf{v}_1^\top+\dots+\sigma_k\mathbf{u}_k\mathbf{v}_k^\top.

Here the subscript counts the pieces kept: Ak\mathbf{A}_k is not the power Ak\mathbf{A}^k, and not a column of A\mathbf{A}. The matrix Ak\mathbf{A}_k has rank kk. And no matrix of rank kk is closer to A\mathbf{A}. This is the Eckart–Young theorem. The error is exactly what was dropped, measured two ways:

  • the largest stretch of the error is the first singular value left out, ∥A−Ak∥2=σk+1\lVert\mathbf{A}-\mathbf{A}_k\rVert_2=\sigma_{k+1};
  • the sum of the squared entries of the error is the sum of the squares left out, ∥A−Ak∥F2=σk+12+σk+22+⋯\lVert\mathbf{A}-\mathbf{A}_k\rVert_\mathrm{F}^2=\sigma_{k+1}^2+\sigma_{k+2}^2+\cdots

The share of the total kept is (σ12+⋯+σk2)/(σ12+σ22+⋯ )(\sigma_1^2+\dots+\sigma_k^2)/(\sigma_1^2+\sigma_2^2+\cdots). In the bar chart of the picture, a few tall bars carry most of it.

A small example

Here is a 3×33\times3 matrix whose pieces have whole-number singular values:

N=[16−2−11414−251416]=27 u1v1⊤+18 u2v2⊤+9 u3v3⊤,\begin{aligned} \mathbf{N}&=\begin{bmatrix}16&-2&-1\\14&14&-2\\5&14&16\end{bmatrix}\\ &=27\,\mathbf{u}_1\mathbf{v}_1^\top+18\,\mathbf{u}_2\mathbf{v}_2^\top\\ &\quad+9\,\mathbf{u}_3\mathbf{v}_3^\top, \end{aligned}

with u1=13(1,2,2)\mathbf{u}_1=\tfrac13(1,2,2), u2=13(2,1,−2)\mathbf{u}_2=\tfrac13(2,1,-2), u3=13(2,−2,1)\mathbf{u}_3=\tfrac13(2,-2,1) and v1=13(2,2,1)\mathbf{v}_1=\tfrac13(2,2,1), v2=13(2,−1,−2)\mathbf{v}_2=\tfrac13(2,-1,-2), v3=13(1,−2,2)\mathbf{v}_3=\tfrac13(1,-2,2). Both sets are orthonormal. Check one pair: Nv1=13(32−4−1,  28+28−2,  10+28+16)=(9,18,18)=27 u1\mathbf{N}\mathbf{v}_1=\tfrac13(32-4-1,\;28+28-2,\;10+28+16)=(9,18,18)=27\,\mathbf{u}_1.

Three tiles

N = 27 u_1 v_{1}ᵀ + 18 u_2 v_{2}ᵀ + 9 u_3 v_{3}ᵀ, one piece at a time.

N_1 = 27 u_1 v_{1}ᵀ: every row is a multiple of (2, 2, 1). The error has size 20.12, and 64.3 % of the energy is kept.

pieces
1
size of the error
20.12
0.00 / 11.20 s
Describe this picture

Two grids of cells side by side, each cell shaded by its number. On the left, N\mathbf{N} rebuilt in three stages: the first piece alone, N1=27 u1v1⊤\mathbf{N}_1=27\,\mathbf{u}_1\mathbf{v}_1^\top, whose rows are all multiples of (2,2,1)(2,2,1); then plus 18 u2v2⊤18\,\mathbf{u}_2\mathbf{v}_2^\top; then plus 9 u3v3⊤9\,\mathbf{u}_3\mathbf{v}_3^\top, which gives N\mathbf{N} exactly. Each cell changes to its new number as a piece is added. On the right, the error N−Nk\mathbf{N}-\mathbf{N}_k, what is still missing, shrinks stage by stage to all zeros. Readouts give the number of pieces and the size of the error: 20.12, then 9, then 0. There is no control.

One piece. N1=[6631212612126]\mathbf{N}_1=\begin{bmatrix}6&6&3\\12&12&6\\12&12&6\end{bmatrix}: every row is a multiple of (2,2,1)(2,2,1). The squared entries of N\mathbf{N} add up to 1134=272+182+921134=27^2+18^2+9^2, and N1\mathbf{N}_1 keeps 729/1134=64.3 %729/1134=64.3\,\% of that. Its error has largest stretch 18 and Frobenius size 182+92=405=20.12\sqrt{18^2+9^2}=\sqrt{405}=20.12.

Two pieces. N2=[142−51610241614]\mathbf{N}_2=\begin{bmatrix}14&2&-5\\16&10&2\\4&16&14\end{bmatrix} keeps 1053/1134=92.9 %1053/1134=92.9\,\%, and its error is the last piece alone:

N−N2=[2−44−24−41−22]=9 u3v3⊤,\begin{aligned} \mathbf{N}-\mathbf{N}_2&=\begin{bmatrix}2&-4&4\\-2&4&-4\\1&-2&2\end{bmatrix}\\ &=9\,\mathbf{u}_3\mathbf{v}_3^\top, \end{aligned}

with Frobenius size 9.

Counting the numbers

A piece σ uv⊤\sigma\,\mathbf{u}\mathbf{v}^\top of an m×nm\times n matrix needs m+n+1m+n+1 numbers: the column, the row and the scale. So Ak\mathbf{A}_k needs k(m+n+1)k(m+n+1), against mnmn for the whole matrix.

  • The 128×128128\times128 picture: 257k257k numbers against 16 384. It saves space only while k<63.75k<63.75; at k=64k=64 it stores 16 448, more than the picture.
  • A 512×512512\times512 picture has 262 144 numbers. Rank 20 needs 20×1025=20 50020\times1025=20\,500, which is 7.8 % of them.

So low rank pays when a few pieces carry most of the picture, as they do for smooth scenes, and not for pure noise.

Limits of low rank

Real image formats do not use the SVD. A JPEG file uses the cosine transform of The discrete cosine transform, a fixed basis that needs no pieces to be stored and costs far less to compute. Low rank is a model: it works when the data really are made of a few patterns, as a ratings table or a set of similar signals often are.

In signal processing · separable filters

An image filter whose kernel is a column times a row is called separable, in Image filtering in the signal processing course. The Sobel kernel is [10−120−210−1]=(1,2,1) (1,0,−1)⊤\begin{bmatrix}1&0&-1\\2&0&-2\\1&0&-1\end{bmatrix}=(1,2,1)\,(1,0,-1)^\top, a rank-one matrix. So it can be run as a column pass and a row pass, 3+3=63+3=6 products per pixel instead of 9.

Worked example

1. The pieces of N\mathbf{N}. Singular values 27, 18 and 9, with the vectors above.

2. Best rank one. N1\mathbf{N}_1 keeps 64.3 % of the squared size; its error is 18 in largest stretch and 20.12 in Frobenius size, which is 0.598 of the whole, 1134\sqrt{1134}.

3. Best rank two. N2\mathbf{N}_2 keeps 92.9 %; its error is 9 u3v3⊤9\,\mathbf{u}_3\mathbf{v}_3^\top, 9 in both measures, 0.267 of the whole.

4. Storage. Rank 20 of a 512×512512\times512 picture stores 20 500 numbers, 7.8 %; break-even is near k=256k=256.

Try these before you read the answers.

  • What is the rank of a column times a row, uv⊤\mathbf{u}\mathbf{v}^\top? 1.
  • A picture whose rows are all equal: how many singular values are not zero? One.
  • The largest-stretch error of the best rank-two approximation of N\mathbf{N}? σ3=9\sigma_3=9.

Where you’ll meet this

Denoising. Measurements of a few true patterns plus noise give a matrix with a few large singular values and many small ones. Keeping the large pieces and dropping the rest removes much of the noise.

Recommendations. A table of ratings, people by items, is close to low rank: tastes come in a few kinds. The best low-rank fit fills in the missing ratings.

Fast filters. A two-dimensional Gaussian blur kernel aligned with the image’s axes is a column times a row, so blurring costs two short passes, not one long one. A Gaussian stretched along a slant is not rank one.

Reference card

QuantityFormulaNotes
PiecesA=∑kσkukvk⊤\mathbf{A}=\sum_k\sigma_k\mathbf{u}_k\mathbf{v}_k^\topeach piece: every row a multiple of one row
Best rank kkAk=∑q≤kσquqvq⊤\mathbf{A}_k=\sum_{q\le k}\sigma_q\mathbf{u}_q\mathbf{v}_q^\topno rank-kk matrix is closer
Largest-stretch error∥A−Ak∥2=σk+1\lVert\mathbf{A}-\mathbf{A}_k\rVert_2=\sigma_{k+1}the first value dropped
Frobenius error∥A−Ak∥F2=∑q>kσq2\lVert\mathbf{A}-\mathbf{A}_k\rVert_\mathrm{F}^2=\sum_{q>k}\sigma_q^2everything dropped
Share kept∑q≤kσq2 / ∑qσq2\sum_{q\le k}\sigma_q^2\,/\,\sum_q\sigma_q^2
Storagek(m+n+1)k(m+n+1) against mnmnpays only for small kk

Keep reading with a free account.

By creating an account you accept the terms of use.

Sign in

Already have an account? Use the service you signed up with.

Or keep reading: get new lessons by email

Are you 13 or over?

Accounts and email updates are for people aged 13 or over. We keep only your answer, never your date of birth.

End of the lesson

Where to go next.

Phasorium

Account

Sign inKeep your place on any device

Subjects

Site

Look