Singular value decomposition (SVD), explained with pictures

A matrix is a plan for changing the plane. It can stretch, shear and rotate it. However complicated a matrix looks, what it does can be split into "turn, stretch, turn again." Split the change from a circle to an ellipse into three steps and watch.

Short answer. Whatever the matrix, what it does can be split into three steps: turn, stretch along the axes, turn again. This is the singular value decomposition A = U Σ Vᵀ. The stretch amounts in the middle, in Σ, are the singular values. Put a circle in and an ellipse comes out. The long radius and the short radius of that ellipse are the singular values.

Left column = where î goes, right column = where ĵ goes

Drag the circles at the arrow tips (î, ĵ) or change the numbers. The dashed circle has radius 1. The colored dots show where the points on that circle go after A. Dots of the same color belong together. The dashed arrows v1 and v2 go to the solid arrows σ1·u1 and σ2·u2, which are the long radius and the short radius of the ellipse.

Definitions

The text below uses 2×2 matrices, but the definitions are the same for m×n matrices. A is a real m×n matrix, and p = min(m, n).

singular value
The n×n matrix AᵀA is symmetric, and all its eigenvalues are 0 or more. Write them from largest to smallest as λ₁ ≥ λ₂ ≥ … ≥ λₙ ≥ 0. The numbers σᵢ below are called the singular values of A. The number of non-zero singular values equals the rank of A.

σi=λi(i=1,…,n)

singular value decomposition (SVD)
Writing A as a product of three matrices as below. U is an m×m orthogonal matrix, V is an n×n orthogonal matrix, and Σ is an m×n matrix with the singular values σᵢ in its (i, i) cells (i = 1, …, p), largest first, and 0 in every other cell. Every real matrix has a singular value decomposition.

A=UΣV𝖳,σ1≥σ2≥⋯≥σp≥0

left singular vector, right singular vector
In a singular value decomposition A = UΣVᵀ, the columns v₁, …, vₙ of V are called the right singular vectors of A, and the columns u₁, …, uₘ of U are called the left singular vectors of A. Writing AV = UΣ one column at a time gives the equation below.

A𝐯i=σi𝐮i(i=1,…,p)

low-rank approximation
If A has rank r, A can be written as a sum of r rank-1 matrices, as in the first formula below. Keeping only the k terms with the largest singular values (k < r) gives Aₖ, called the rank-k approximation of A. If you measure distance by squaring the difference in every cell, adding them all up, and taking the square root, Aₖ is the closest matrix to A among all matrices of rank k or less.

A=σ1𝐮1𝐯1𝖳+σ2𝐮2𝐯2𝖳+⋯+σr𝐮r𝐯r𝖳

Ak=σ1𝐮1𝐯1𝖳+⋯+σk𝐮k𝐯k𝖳

1. A circle becomes an ellipse

A matrix A moves every point on the plane (as on the determinant page). Move the points of a circle with radius 1 with A, and you always get an ellipse. If the matrix squashes the plane, that ellipse is pressed into a line segment or even a single point.

An ellipse has a longest direction and a shortest direction, and they are at a right angle. Trace back which points on the circle land there, and you find two directions v1 and v2. These two are also at a right angle. In short:

Keeping a right angle is not common. î and ĵ are at a right angle too, but after A they usually are not (look at the green and blue arrows in the lab). If σ1 and σ2 are different, there is only one pair that keeps its right angle (an arrow and its reverse count as the same direction). The amounts σ1 and σ2 by which these two directions are stretched are the singular values. The larger one is called σ1.

2. The formula: A = U Σ Vᵀ

Write section 1 as a product of three matrices, and you have the singular value decomposition.

A=UΣV𝖳

PieceWhat it doesIn a 2×2 matrix
VᵀTurns the input. Sends v1 and v2 onto the across axis and the up axisIts rows are v1 and v2
Σ (sigma)Stretches along the axes. The singular values sit on its diagonal[σ1 0 / 0 σ2]
UTurns again. Sends the across axis and the up axis to u1 and u2Its columns are u1 and u2

When you multiply a point x by A, things happen from right to left: A x = U (Σ (Vᵀ x)). First Vᵀ, then Σ, and last U. That is why it is "turn, stretch, turn again."

One direction at a time, it says A v1 = σ1 u1 and A v2 = σ2 u2. You can also write A as a sum of pieces:

A=σ1𝐮1𝐯1𝖳+σ2𝐮2𝐯2𝖳

Each piece (u1 v1ᵀ) is the simplest kind of matrix: it presses the whole plane onto one line. σ is the weight of that piece. The "drop the small one" idea in section 7 comes from here.

The ᵀ in Vᵀ means transpose: swap the rows and the columns. The columns of V are v1 and v2, so the rows of Vᵀ are v1 and v2. U and V only turn (and sometimes flip), so they never change lengths or right angles.

3. Watch the three steps

Slowly move the "Step" slider from 0 to 3, or press "Play the three steps."

  1. Turn with Vᵀ (0 to 1). A turned circle is still a circle, so the shape stays the same and only the colored dots move around. At the end of this step, v1 lies on the across axis and v2 lies on the up axis.
  2. Stretch with Σ (1 to 2). Across is multiplied by σ1, up and down by σ2. The circle becomes an ellipse lined up with the axes.
  3. Turn with U (2 to 3). The ellipse is turned into its final place. The across axis goes to u1 and the up axis goes to u2.

When a flip is mixed in. If the determinant is negative, A flips the plane over. Turning alone can never flip, so one of U and V carries a flip. In the numbers, the lab puts the flip in Vᵀ. In the picture, it shows the flip during step ②: up and down is multiplied by −σ2. The circle becomes a flat line for a moment and comes out as its mirror image.

Try this. ① The lab starts with "Shear," [1 1 / 0 1]. σ1 = 1.62 and σ2 = 0.62, and their product is 1, the same as the determinant. Press "Play the three steps." Step ① turns 58° clockwise, step ② stretches 1.62 times across and 0.62 times up and down, and step ③ turns 32° counterclockwise. ② "2× across, 0.5× up" is already a stretch along the axes, so steps ① and ③ have nothing to turn (0°). ③ In "Flip," [0 2 / 1 0], slowly move the slider from 1 to 2. The circle grows across and gets pressed up and down into a line, then comes out again as its mirror image. ④ Drag the tip of î onto the same line as ĵ. σ2 becomes 0 and the rank drops to 1.

4. How the formula is built: find the direction that stretches the most

In section 1, v1 was the direction A stretches the most, and σ1 was how much it stretches there. If you find that direction with a formula instead of by turning and measuring, you can see why the singular values are the square roots of the eigenvalues of AᵀA, and where A v = σ u and A = U Σ Vᵀ come from. The matrix is the shear [1 1 / 0 1], the one the lab above starts with.

Press "Next" to go one step at a time. A piece is added to the formula on top (the orange background marks the new piece), the picture changes by that much, and the reason appears below. In the left picture, the dashed circle has radius 1, the gray dashed arrow is v on the circle, and the black solid arrow is A v. In the right graph, across is the angle θ of v and up is the length of A v (its square in steps 2 and 3). The faint lines are the graph before and after squaring. Orange is the peak side (v1) and purple is the valley side (v2).

Written only as equations, the steps above look like this.

‖A𝐯‖2=(A𝐯)𝖳(A𝐯)=𝐯𝖳(A𝖳A)𝐯,‖𝐯‖=1

A=[1101]:A𝖳A=[1011][1101]=[1112]

A𝖳A𝐯i=λi𝐯i:λ2−3λ+1=0⟹λ1=3+52≈2.62, λ2=3−52≈0.38

σi=λi:σ1=2.62≈1.62, σ2=0.38≈0.62

𝐮i=A𝐯iσi⟹A𝐯i=σi𝐮i

A[𝐯1𝐯2]=[𝐮1𝐮2][σ100σ2]⟺AV=UΣ

AV=UΣ,VV𝖳=I⟹A=AVV𝖳=UΣV𝖳

  1. Measure while turning: |A v|. Write the arrow of length 1 on the circle at angle θ as v = (cos θ, sin θ). At θ = 0°, v = (1, 0) and A v = (1, 0), with length 1. At θ = 90°, v = (0, 1) and A v = (1, 1), with length 1.41. Turn v from 0° to 180°, and the length goes up and down between 0.62 and 1.62 while the tip of A v draws an ellipse. Past 180°, v becomes −v and the same lengths repeat, so half a turn is enough. The peak, 1.62, is σ1, and the valley, 0.62, is σ2. A big matrix has too many directions to try one by one, so we need a formula.
  2. Square it: |A v|² = vᵀ (AᵀA) v. The squared length of an arrow w is its dot product with itself, w·w = wᵀ w (see dot product). Put A v in for w. A transpose flips the order of a product, (A v)ᵀ = vᵀ Aᵀ, so |A v|² = vᵀ Aᵀ A v. For the shear, AᵀA = [1 1 / 1 2]. At θ = 0°, vᵀ(AᵀA)v is the top-left entry, 1. At 90° it is the bottom-right entry, 2 (= 1.41²). Lengths are never negative, so squaring does not move the peak or the valley. From here on you only need one matrix, AᵀA, instead of A.
  3. The peak is an eigenvector: AᵀA v = λ v. At the peak (58°) the graph is flat: turn v a little and the value does not change. When v turns a little, it moves at a right angle to itself, and how fast the value changes is set by the part of AᵀA v in that right-angle direction (calculus shows this; we do not prove it here). For the graph to be flat, that part must be 0, so AᵀA v must point the same way as v. In the picture, that is where the orange arrow AᵀA v lies on top of v. An arrow that keeps its direction is an eigenvector, and the value there is vᵀ (λ v) = λ (v has length 1), which is the eigenvalue. At the peak, λ1 = 2.62. The valley (148°) is flat too, so for the same reason it is an eigenvector, with λ2 = 0.38.
  4. Take the square root: σ = √λ. Step 2 squared the length, so undo it. σ1 = √2.62 = 1.62 and σ2 = √0.38 = 0.62, the same values measured in step 1. This is "singular values = square roots of the eigenvalues of AᵀA." The peak and the valley are always 90° apart. Write vᵀ(AᵀA)v in terms of θ and tidy it up with cos 2θ and sin 2θ, and you get a single wave that goes up and down once every 180°. So v1 and v2 are at a right angle. For big matrices, the same job is done by the fact that the eigenvectors of a symmetric matrix are at right angles to each other (we do not prove it here).
  5. Make u: A v = σ u. A v1 has length σ1, so dividing it by σ1 leaves a direction of length 1. Call it u1. u1 = A v1 ÷ σ1 = (1.38, 0.85) ÷ 1.62 = (0.85, 0.53) and u2 = A v2 ÷ σ2 = (-0.32, 0.53) ÷ 0.62 = (-0.53, 0.85) (dividing the rounded numbers gives slightly different last digits). Written the other way, A v = σ u. u1 and u2 are at a right angle too, because (A v1)·(A v2) = v1ᵀ (AᵀA) v2 = λ2 (v1·v2) = 0. If σ is 0 you cannot divide, so that u is chosen as an arrow of length 1 at a right angle to the other u.
  6. Put it together: A = U Σ Vᵀ. Stand the two equations A v1 = σ1 u1 and A v2 = σ2 u2 side by side as columns: A [v1 v2] = [u1 u2] [σ1 0 / 0 σ2], which is A V = U Σ. The columns v1 and v2 of V are arrows of length 1 at a right angle, so V Vᵀ = I. Multiply both sides by Vᵀ on the right, and you get A = U Σ Vᵀ. In numbers, U = [0.85 -0.53 / 0.53 0.85], Σ = [1.62 0 / 0 0.62] and Vᵀ = [0.53 0.85 / -0.85 0.53], the same as the readout in the lab above. Multiply the three and î goes to (1, 0) and ĵ goes to (1, 1), just like A. The order used by hand in section 6 (AᵀA, then eigenvalues, then square roots, then u = A v ÷ σ) is exactly this path.

5. Properties to know

PropertyWhat it means
Singular values are always 0 or more, written largest first (σ1 ≥ σ2 ≥ 0)They are stretch amounts, so they are never negative. Pointing the other way is the job of U or V. For example, the singular values of [−3 0 / 0 1] are also 3 and 1
An arrow of length 1 ends up with a length between σ2 and σ1σ1 is the most A stretches anything, and σ2 is the least. Whatever direction you put in, the result is in between
σ1 × σ2 = |determinant| (2×2)A circle with area π becomes an ellipse with area π × σ1 × σ2. The determinant tells you what area gets multiplied by, so the two match. The lab's readout always shows them equal
The number of singular values that are not 0 = the rankEach direction that gets squashed flat has a singular value of 0. Press "Squash": σ2 = 0 and the rank is 1 (see rank)
Singular values = square roots of the eigenvalues of AᵀAAᵀA is the matrix that gives the squared stretched length |A x|². The v's are eigenvectors of AᵀA, and the u's are eigenvectors of AAᵀ. Section 4 shows where this comes from, one step at a time

6. Work one out by hand

An easy one: [3 0 / 0 1]

This matrix multiplies across by 3 and up and down by 1. It is already a stretch along the axes, so there is nothing to turn. So U = [1 0 / 0 1], Σ = [3 0 / 0 1], Vᵀ = [1 0 / 0 1], and the singular values are 3 and 1. The circle becomes an ellipse with radius 3 across and radius 1 up and down.

One step further: A = [0 2 / 1 0]

This matrix sends î to (0, 1) and ĵ to (2, 0). Follow along step by step.

  1. Find Aᵀ. Swap the rows and the columns. Aᵀ = [0 1 / 2 0]
  2. Multiply AᵀA. AᵀA = [0×0+1×1 0×2+1×0 / 2×0+0×1 2×2+0×0] = [1 0 / 0 4]
  3. Find the eigenvalues of AᵀA. It is a diagonal matrix, so the diagonal entries are the eigenvalues. Largest first: 4, 1.
  4. Their square roots are the singular values. σ1 = √4 = 2, σ2 = √1 = 1
  5. The eigenvectors are the v's. For eigenvalue 4, v1 = (0, 1). For eigenvalue 1, v2 = (1, 0)
  6. For each u, put v into A and divide by σ. u1 = A v1 ÷ σ1 = (2, 0) ÷ 2 = (1, 0), u2 = A v2 ÷ σ2 = (0, 1) ÷ 1 = (0, 1)
  7. Put it together. U = [1 0 / 0 1] (columns u1, u2), Σ = [2 0 / 0 1], Vᵀ = [0 1 / 1 0] (rows v1, v2)
  8. Check. U × Σ × Vᵀ = [2 0 / 0 1] × [0 1 / 1 0] = [0 2 / 1 0], which is A. σ1 × σ2 = 2 and |determinant| = |0×0 − 2×1| = 2, so they match.

Written as equations, the same solution looks like this.

A𝖳A=[0120][0210]=[1004],λ1=4, λ2=1

σ1=4=2,σ2=1=1,𝐯1=[01],𝐯2=[10]

𝐮1=A𝐯1σ1=12[20]=[10],𝐮2=A𝐯2σ2=11[01]=[01]

UΣV𝖳=[1001][2001][0110]=[0210]=A

σ1σ2=2=|detA|=|0×0−2×1|

In equations, (0, 1) is written standing up, as a column. It is the same arrow.

Vᵀ = [0 1 / 1 0] is a flip that swaps across and up. The determinant is −2, which is negative, so there is one flip inside. Press "Flip" in the lab and you get the same U, Σ and Vᵀ.

If AᵀA is not diagonal, find its eigenvalues the way the eigenvectors page shows. For a 2×2 matrix, solve λ² − (sum of the diagonal) × λ + (determinant) = 0.

7. Drop the small ones: low-rank approximation

In the formula from section 2, A = σ1 u1 v1ᵀ + σ2 u2 v2ᵀ, if σ2 is small, the second piece adds only a little to A. Drop that piece, and what is left, A₁ = σ1 u1 v1ᵀ, is a matrix of rank 1: it presses the plane onto one line.

This A₁ is the closest matrix to A among all matrices of rank 1. The size of what you dropped, A − A₁ = σ2 u2 v2ᵀ, is exactly σ2 (size here means: square the four differences, add them, take the square root). No matrix of rank 1 is closer to A.

The same holds for big matrices. Keep only the k largest singular values, and you get the closest matrix to the original among all matrices of rank k (the Eckart-Young theorem). You also store fewer numbers. A 1000×1000 matrix holds 1 million numbers. Keep k = 50, and you need 50 u's (50,000 numbers), 50 v's (50,000) and 50 σ's: 100,050 numbers in all, about 10% of the original.

Try this. In "Shear," turn on "Drop the small one." The ellipse becomes a line segment. The matrix left is [0.72 1.17 / 0.45 0.72], A minus that is [0.28 -0.17 / -0.45 0.28], and the size of the difference is σ2 = 0.62. Turn it on in "2× across, 0.5× up" and you get [2 0 / 0 0]: the up-and-down part, which stretches less, is dropped. In "Squash," σ2 is already 0, so nothing changes.

8. How is this different from eigenvalues?

An eigenvector is "an arrow whose direction stays the same after A," and its eigenvalue is how much that arrow is stretched. That sounds close to singular values, but it is different.

EigendecompositionSingular value decomposition
Works forSome square matricesEvery matrix (rectangular ones too)
DirectionsThe direction going in is the direction coming out. Eigenvectors may not be at right angles to each otherThe direction going in (v) and coming out (u) can differ. The v's are always at right angles to each other, and so are the u's
Stretch amountsCan be negative or complexAlways real numbers of 0 or more
FormulaA = P D P⁻¹ (columns of P are eigenvectors, the diagonal of D holds the eigenvalues)A = U Σ Vᵀ

The link between them: singular values = square roots of the eigenvalues of AᵀA (see section 4). If A is symmetric (A = Aᵀ), the singular values are the absolute values of the eigenvalues.

For example, the shear [1 1 / 0 1] has only one eigenvalue, 1, and only one eigenvector direction, (1, 0), so it has no eigendecomposition. Its singular values still come out fine: 1.62 and 0.62. A rotation matrix that is not 0° or 180° turns every direction, so it has no real eigenvectors. Its singular values are 1 and 1.

Where is it used?

Common questions

What is the singular value decomposition (SVD)?

It splits what any matrix does into three steps: turn, stretch along the axes, turn again. It is written A = U Σ Vᵀ. U and V turn (and sometimes flip). The stretch amounts on the diagonal of Σ are the singular values.

How are singular values different from eigenvalues?

Eigenvalues exist only for square matrices, and they can be negative or complex. The eigendecomposition works only for some of those matrices. Every matrix has singular values, and they are always real numbers of 0 or more. The singular values are the square roots of the eigenvalues of AᵀA.

What does a singular value of 0 mean?

It means that direction has been squashed flat and is gone. The number of singular values that are not 0 is the rank. If a square matrix has a singular value of 0, its determinant is also 0, so it has no inverse.

Are U and V unique?

No. You can reverse a matching pair u and v together, and the answer is still right. If two singular values are equal, there are even more directions to choose from. The singular values themselves are always unique.

Does it work for matrices that are not square?

Yes. For an m×n matrix, U is m×m, Σ is m×n, and V is n×n. There are as many singular values as the smaller of m and n.

Words

Word used hereWord used in textbooks
splitting into turn, stretch, turn againsingular value decomposition (SVD)
stretch amounts σ1, σ2singular values
the two input directions v1, v2right singular vectors
the two output directions u1, u2left singular vectors
a matrix that only turns (sometimes flips), like U and Vorthogonal matrix
a matrix with numbers only on its diagonal, like Σdiagonal matrix
the matrix with rows and columns swappedtranspose. Written Aᵀ
the number of directions that are not squashedrank
dropping the small oneslow-rank approximation, truncated SVD
an arrow whose direction stays the same, and how much it is stretchedeigenvector and eigenvalue
an "undo" matrix you can use even when there is no inversepseudoinverse (Moore-Penrose inverse). Written A⁺
finding the directions where data spreads the mostprincipal component analysis (PCA)

← Projection and least squaresTensors and shapes: axes, shape and broadcasting →