MathAlgebraLinear algebraMatrix decomposition

Singular value decomposition

9 minutes read

This is the deepest, most universal, and most widely used theorem in all linear algebra applications. Absolutely any matrix admits this decomposition. Once you calculate it, you have access to almost all of its properties, from its range to its inverse, through its determinant and a complete interpretation of its associated linear transformation.
In a sense, this is why you've been learning linear algebra. In this introductory topic, you'll analyze this decomposition in detail, learn how to calculate it efficiently, and finally take a look at the first sample of its geometric implications. In the next topic, you'll see its power in action.

The best decomposition

For any m×nm \times n matrix AA , there exist orthogonal matrices UU and VV (of sizes mm and nn, respectively), and a diagonal m×nm \times n matrix Σ\Sigma with non-negative entries, such that:
A=UΣVT\begin{align*} A=U \Sigma V^T \end{align*}

The pieces of the decomposition

The fact that the rectangular matrix Σ\Sigma is meant to be diagonal simply means that its (i,j)(i,j)-entry is 00 whenever iji \neq j. This decomposition brings with it a bit of terminology that's worth knowing now.

Concept Name Definition

The diagonal entries of Σ\Sigma

Singular values of AA

The non-negative square roots of the eigenvalues of AATA \, A^T.

The columns of UU

Left singular vectors of AA

The eigenvectors of AATA \, A^T

The columns of VV

Right singular vectors of AA

The eigenvectors of ATAA^T \, A

Proof of the singular value decomposition

You can suppose that mnm \geq n and work with ATAA^T \, A—otherwise, you only need to use AATA \, A^T. Well, as you already know, the n×nn \times n matrix ATAA^T \, A is positive semidefinite. Thus it has a spectral decomposition ATA=VDVTA^T \, A = VDV^T with nn non-negative eigenvalues d1,d2,,dnd_1, d_2, \dots, d_n in the diagonal of DD.

Thanks to this fact, you can build the m×nm \times n matrix Σ\Sigma by putting its (j,j)(j,j)-entry as dj\sqrt{d_j} and as 00 otherwise. Of course, Σ\Sigma is the principal square root of DD but with extra zero rows so that it has the same number of rows as AA. Then ΣTΣ=D\Sigma^T \Sigma = D and this implies that:

ATA=VDVT=VΣTΣVT=(ΣVT)TΣVTA^T \, A = VDV^T = V \Sigma^T \Sigma V^T = (\Sigma V^T)^T \Sigma V^TTake a closer look at the last equation. You have just proved that ATA=(ΣV)TΣVTA^T \, A = (\Sigma V)^T \Sigma V^T. This is the orthogonal freedom, so there exists an orthogonal matrix UU such that A=UΣVTA=U \Sigma V^T. Yes, you have built the decomposition.

But you aren't done yet. You have to justify the terminology of the pieces. When the decomposition is ready, it's clear that:

ATA=(UΣVT)TUΣVT=V(ΣTΣ)VTA^T \, A = (U \Sigma V^T )^TU \Sigma V^T =V(\Sigma^T \Sigma) V^TSince this is a diagonalization of ATAA^T \, A, it follows that the columns of VV are eigenvectors for AA and the entries in the main diagonal of ΣTΣ\Sigma^T \Sigma are the corresponding eigenvalues. You can easily verify the corresponding statements about UU and AATA \, A^T very similarly.

\blacksquare

Actually, these definitions give you a rough method to calculate the decomposition:

  1. Compute AATA \, A^T and ATAA^T \, A.
  2. Find the eigenvalues of both AATA \, A^T and ATAA^T \, A (they share the same eigenvalues).
  3. Calculate the non-negative roots of these eigenvalues. Then put them in the diagonal entries of a matrix Σ\Sigma.
  4. Compute the eigenvectors of AATA \, A^T and scale them in order to have length 11. Put them as the columns of UU.
  5. Repeat the last step for ATAA^T \, A building the matrix VV.
  6. Finally, A=UΣVTA=U \Sigma V^T.

In the following section, you'll develop a much shorter algorithm.

Building the decomposition

The method from the previous section has a serious drawback: you have to build two matrices, AATA \, A^T and ATAA^T \, A, and then build a spectral decomposition for each one. This sounds like a lot of work. Let's take a closer look at the pieces of the decomposition in order to improve the algorithm.

It's customary to denote the singular values as σ1,σ2,,σn\sigma_1, \sigma_2, \dots, \sigma_n and to order them in non-increasing order σ1σ2σmin(m.n)\sigma_1 \geq \sigma_2 \dots \geq \dots \sigma_{\min(m.n)}. .

Since Σ\Sigma is diagonal, its rank is the number of nonzero rows it has, which is, therefore, the number of non-zero singular values of AA. Well, if rr is the rank of AA, then r=rank(A)=rank(UΣVT)=rank(Σ)r= rank(A) = rank(U \Sigma V^T) = rank(\Sigma), thus:

The number of non-zero singular values of AA is exactly the rank rr of AA

Thus, σ1σ2σr>0\sigma_1 \geq \sigma_2 \dots \geq \dots \sigma_r >0 and σr+1==σmin(m.n)=0\sigma_{r+1} = \dots= \sigma_{\min(m.n)} =0. Let's analyze the pieces by expressing UU and VV in terms of its columns:

U=[u1u2um]U = \left[\begin{array}{l|l|l|l} \mathbf{u}_1 & \mathbf{u}_2 & \cdots & \mathbf{u}_m \end{array}\right]

V=[v1v2vn]V=\left[\begin{array}{l|l|l|l} \mathbf{v}_1 & \mathbf{v}_2 & \cdots & \mathbf{v}_n \end{array}\right]The matrix equation A=UΣVTA=U \Sigma V^T implies that AV=UΣA V=U \Sigma. Take a closer look at the columns of these new matrices:

AV=[Av1Av2Avn]A V =\left[\begin{array}{l|l|l|l} A \mathbf{v}_1 & A \mathbf{v}_2 & \cdots & A \mathbf{v}_n \end{array}\right]UΣ=[σ1u1σ2u2σrur00]U \Sigma = \left[\begin{array}{l|l|l|l|l|l|l} \sigma_1 \mathbf{u}_1 & \sigma_2 \mathbf{u}_2 & \cdots &\sigma_r \mathbf{u}_r & 0 & \cdots &0 \end{array}\right]

Since these two matrices are equal, their columns are equal too. This implies that the first rr columns of UU can be obtained by:
uj=1σjAvj for all j{1,2,,r}\mathbf{u}_j=\frac{1}{\sigma_j} A \mathbf{v}_j \quad \text { for all } \quad j \in \{1, 2, \dots, r\}Then the rest of the columns of UU can be calculated by extending the available ones so that they form an orthonormal basis. So, you have developed an easier method to get the decomposition:

  1. Start by computing ATAA^T \, A
  2. Build a spectral decomposition for this matrix:ATA=V(ΣTΣ)VTA^T \, A =V(\Sigma^T \Sigma) V^T by ordering the positive singular values in decreasing order
  3. Compute uj=1σjAvj\mathbf{u}_j=\frac{1}{\sigma_j} A \mathbf{v}_j for every j{1,2,,r}j \in \{1, 2, \dots, r\}.
  4. Extend the set {u1,u2,,ur}\{ \mathbf{u}_1, \mathbf{u}_2, \dots, \mathbf{u}_r \} to an orthonormal basis and put the vectors as the columns of UU.

Now, you should get your hands dirty with some examples.

A direct example

Consider the following rectangular matrix:

A=(111111)A= \begin{pmatrix} 1 & 1 & -1 \\ -1 & 1 & 1 \\ \end{pmatrix}The first step is computing a spectral decomposition for the positive definite matrix:

ATA=(202020202)A^T A=\begin{pmatrix} 2 & 0 & -2 \\ 0 & 2 & 0 \\ -2 & 0 & 2 \end{pmatrix}Its eigenvalues are 44, 22 and 00. This means the singular values of AA are their square roots, so σ1=4=2\sigma_1 = \sqrt{4} = 2 and σ2=2\sigma_2 = \sqrt{2}. This also implies that rank(A)=2rank(A)=2 since there are only two positive singular values. Now, an orthonormal basis corresponding to the eigenvalues is:

v1=12(101)v2=12(020)v3=12(101)\mathbf{v}_1= \frac{1}{\sqrt{2}} \begin{pmatrix} -1 \\ 0 \\ 1 \end{pmatrix} \qquad \mathbf{v}_2= \frac{1}{\sqrt{2}} \begin{pmatrix} 0 \\ \sqrt{2} \\ 0 \end{pmatrix} \qquad \mathbf{v}_3= \frac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ 0 \\ 1 \end{pmatrix}Now put these vectors as the columns of the matrix VV and the singular values on the diagonal of the matrix Σ\Sigma:

Σ=(200020)V=12(101020101)\Sigma= \begin{pmatrix} 2 & 0 & 0 \\ 0 & \sqrt{2} & 0 \end{pmatrix} \qquad V= \frac{1}{\sqrt{2}} \begin{pmatrix} -1 & 0 & 1 \\ 0 & \sqrt{2} & 0 \\ 1 & 0 & 1 \end{pmatrix}After that, the two columns of UU can be obtained via:

  • u1=1σ1Av1=12(111111)[12(101)]=12(11)u_1 = \frac{1}{\sigma_1} A \mathbf{v}_1 = \frac{1}{2} \begin{pmatrix} 1 & 1 & -1 \\ -1 & 1 & 1 \\ \end{pmatrix} \left[ \frac{1}{\sqrt{2}} \begin{pmatrix} -1 \\ 0 \\1 \end{pmatrix} \right] = \frac{1}{\sqrt{2}} \begin{pmatrix} -1 \\ 1\end{pmatrix}
  • u2=1σ2Av2=12(111111)[12(020)]=12(11)u_2 = \frac{1}{\sigma_2} A \mathbf{v}_2 = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 & -1 \\ -1 & 1 & 1 \\ \end{pmatrix} \left[ \frac{1}{\sqrt{2}} \begin{pmatrix} 0 \\ \sqrt{2} \\0 \end{pmatrix} \right] = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ 1\end{pmatrix}

Hence:
U=12(1111)U=\frac{1}{\sqrt{2}} \begin{pmatrix} -1 & 1 \\ 1 & 1 \\ \end{pmatrix}And that's it. The SVD decomposition of AA is complete. You should verify that A=UΣVTA=U \Sigma V^T.

More steps

Let's see a more difficult decomposition. Take a square matrix:

A=(222414424)A= \begin{pmatrix} 2 & 2 & -2 \\ -4 & -1 & 4 \\ -4 & 2 & 4 \\ \end{pmatrix}Start by computing the positive definite matrix:

ATA=(3603609036036)A^T A=\begin{pmatrix} 36 & 0 & -36 \\ 0 & 9 & 0 \\ -36 & 0 & 36 \\ \end{pmatrix}Since its eigenvalues are 7272, 99 and 00, the singular values of AA are their square roots σ1=62\sigma_1 = 6 \sqrt{2} and σ2=3\sigma_2 = 3. An orthonormal basis corresponding to these eigenvalues is:

v1=12(101)v2=12(020)v3=12(101)\mathbf{v}_1= \frac{1}{\sqrt{2}} \begin{pmatrix} -1 \\ 0 \\ 1 \end{pmatrix} \qquad \mathbf{v}_2= \frac{1}{\sqrt{2}} \begin{pmatrix} 0 \\ \sqrt{2} \\ 0 \end{pmatrix} \qquad \mathbf{v}_3= \frac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ 0 \\ 1 \end{pmatrix}Now you can build matrices Σ\Sigma and VV:

Σ=(6200030000)V=12(101020101)\Sigma= \begin{pmatrix} 6 \sqrt{2} & 0 & 0 \\ 0 & 3 & 0 \\ 0 & 0 & 0 \end{pmatrix} \qquad V= \frac{1}{\sqrt{2}} \begin{pmatrix} -1& 0 &1 \\ 0 & \sqrt{2} & 0 \\ 1 & 0 &1\\ \end{pmatrix}But AA only has two singular values, so you can only compute the first two columns of UU:

u1=1σ1Av1=162(222414424)[12(101)]=13(122)u_1 = \frac{1}{\sigma_1} A \mathbf{v}_1 = \frac{1}{6\sqrt{2}} \begin{pmatrix} 2 & 2 & -2 \\ -4 & -1 & 4 \\ -4 & 2 & 4 \\ \end{pmatrix}\left[ \frac{1}{\sqrt{2}} \begin{pmatrix} -1 \\ 0 \\1 \end{pmatrix} \right] = \frac{1}{3} \begin{pmatrix}-1 \\ 2 \\ 2 \end{pmatrix}u2=1σ2Av2=13(222414424)[12(020)]=13(212)u_2 = \frac{1}{\sigma_2} A \mathbf{v}_2 = \frac{1}{3} \begin{pmatrix} 2 & 2 & -2 \\ -4 & -1 & 4 \\ -4 & 2 & 4 \\ \end{pmatrix}\left[ \frac{1}{\sqrt{2}} \begin{pmatrix} 0 \\ \sqrt{2} \\ 0 \end{pmatrix}\right] = \frac{1}{3} \begin{pmatrix} 2 \\ -1 \\ 2 \end{pmatrix}You can find the last column of UU by extending {u1,u2}\{ \mathbf{u}_1, \mathbf{u}_2 \} to an orthonormal basis of R3\mathbb{R}^3, perhaps with the Gram-Schmidth process or with the cross product. This can lead you to the vector u3=13(2,2,1)T\mathbf{u}_3= \frac{1}{3}(-2, -2,1) ^T. Thus:

U=13(122212221)U = \frac{1}{3} \begin{pmatrix} -1& 2 &-2 \\ 2 & -1 & -2 \\ 2 & 2 &1\\ \end{pmatrix}Again, try to check that A=UΣVTA=U \Sigma V^T.

Geometry

You can easily decompose the geometric behavior of any matrix AA in simple steps. First, notice that the linear operator of AA is given by the following composition of simpler pieces:LA=LULDLVTL_A=L_U \circ L_D \circ L_{V^T}So, the behavior of LAL_A is described by three stages:

  • As VTV^T is orthogonal, the action of LVTL_{V^T} is just a rotation and/or reflection of Rm\mathbb{R}^m,
  • after that, the fact that DD is diagonal implies that LDL_D only stretches and then embeds Rm\mathbb{R}^m in Rn\mathbb{R}^n,
  • finally LUL_{U} is a rotation and/or reflection of Rn\mathbb{R}^n,.

Furthermore, the two radii of the ellipse are exactly the singular values σ 1 and σ 2 of the matrix,

The geometry of any matrix

Conclusion

Take a m×nm \times n matrix AA with a rank equal to rr.

  • There are orthogonal matrices UU and VV (of sizes mm and nn, respectively), and a diagonal m×nm \times n matrix Σ\Sigma with non-negative entries, such that A=UΣVTA=U \Sigma V^T.

  • The diagonal entries of Σ\Sigma are the singular values of AA.

  • There are exactly rr non-zero singular values which are in decreasing order σ1σ2σr>0\sigma_1 \geq \sigma_2 \dots \geq \dots \sigma_r >0.

  • In order to compute the decomposition, you first calculate a spectral decomposition for ATA=VDVTA^T A= VDV^T and then the first rr columns of UU are given by uj=1σjAvj\mathbf{u}_j=\frac{1}{\sigma_j} A \mathbf{v}_j.

  • The geometry of the linear transformation associated with AA is the composition of an isometry, a stretching, and other isometry.

3 learners liked this piece of theory. 0 didn't like it. What about you?
Report a typo