Proba ML
7. Linear Algebra
7.5 Singular Valye Decomposition (SVD)

7.5 Singular Value Decomposition (SVD)

SVD generalizes EVD to rectangular matrices. Even for square matrices, an EVD does not always exist, whereas an SVD always exists.

7.5.1 Basics

Any real m×nm\times n matrix can be decomposed as:

A=USV=σ1[u1][v1]++σr[ur][vr]A=USV^\top=\sigma_1 \begin{bmatrix}| \\u_1 \\ |\end{bmatrix} \begin{bmatrix}— v_1^\top—\end{bmatrix}+\dots+\sigma_r \begin{bmatrix}| \\u_r \\ |\end{bmatrix} \begin{bmatrix}— v_r^\top—\end{bmatrix}

with UUand VV orthogonal matrices (left and right singular vectors):

  • UU=ImUU^\top=I_m
  • VV=InVV^\top=I_n
  • SS is a m×nm\times n matrix, containing the rank r=min(m,n)r=\min(m,n) singular values σi0\sigma_i\geq0.

Screen Shot 2023-03-26 at 17.35.40.png

The cost of computing the SVD is O(min(mn2,m2n))O(\min(mn^2,m^2n))

7.5.2 Connection between EVD and SVD

If AA is real, symmetric, and positive definite, then the singular values are equal to the eigenvalues:

A=USV=USUA=USV^\top=USU^\top

More generally, we have:

AA=(VSU)(USV)=V(SS)VA^\top A= (VS^\top U^\top)(USV^\top)=V(S^\top S)V^\top

Hence:

(AA)V=VDn(A^\top A) V= V D_n
  • evec(AA)=V\mathrm{evec}(A^\top A)=V and evec(AA)=U\mathrm{evec}(A A^\top)=U
  • eval(AA)=Dn\mathrm{eval(A^\top A})=D_n and eval(AA)=Dm\mathrm{eval(AA^\top})=D_m
  • In the economy size SVD: D=S2=SS=SSD=S^2=S^\top S=S^\top S

7.5.3 Pseudo inverse

The Moore-Penrose pseudo-inverse of AA is denoted AA^\dagger and has the following properties:

AAA=AAAA=A(AA)=AA(AA)=AA\begin{align} AA^\dagger A&= A \\ A^\dagger A A^\dagger&=A^\dagger \\ (A A^\dagger)^\top&=A A^\dagger \\ (A^\dagger A)^\top &=A^\dagger A \end{align}

If AA is square and non-singular, then A=A1A^\dagger=A^{-1}

If m>nm>n and all columns of AA are linearly independent (i.e. AA is full-rank):

A=(AA)1AA^\dagger=(A^\top A)^{-1}A^\top

In this case, AA^\dagger is the left inverse of AA (but not its right inverse):

AA=IA^\dagger A=I

We can also compute the pseudo-inverse using the SVD:

A=Vdiag([1/σ1,,1/σr,0,,0])UA^\dagger=V \mathrm{diag}(\begin{bmatrix}1/\sigma_1,\dots,1/\sigma_r,0,\dots,0\end{bmatrix} )U^\top

When n<mn<m, the right inverse of AA is:

A=A(AA)1A^\dagger=A^\top(AA^\top)^{-1}

and we have:

AA=IAA^\dagger=I

7.5.4 SVD and the range and null space

We show that the left and right singular vectors form an orthonormal basis for the range and nullspace.

We have:

Ax=j=1rσj(vjx)ujA\bold{x}=\sum_{j=1}^r \sigma_j (\bold{v}_j^\top \bold{x})\bold{u}_j

where rr is the rank of AA.

Thus AxA\bold{x} can be written as any linear combination of left singular vectors u1,...,ur\bold{u_1},...,\bold{u_r}:

range(A)=span({uj:σj>0})\mathrm{range}(A)=\mathrm{span}(\{\bold{u}_j:\sigma_j>0\})

with dimension rr.

For the nullspace, we define yRn\bold{y}\in\mathbb{R}^n as a linear combination of the right singular vectors for the zero singular values:

y=j=r+1ncjvj\bold{y}=\sum_{j=r+1}^n c_j \bold{v}_j

Then:

Ay=U[σ1v1yσrvryσr+1vr+1yσnvny]=U[σ10σr00vr+1y0vny]=U0=0A\bold{y}=U\begin{bmatrix}\sigma_1 \bold{v}_1^\top \bold{y} \\ \vdots \\ \sigma_r \bold{v}_r^\top \bold{y} \\ \sigma_{r+1} \bold{v}_{r+1}^\top \bold{y} \\ \vdots \\ \sigma_n \bold{v}_n^\top \bold{y}\end{bmatrix}=U\begin{bmatrix}\sigma_1 0 \\ \vdots \\ \sigma_r 0 \\ 0 \bold{v}_{r+1}^\top \bold{y} \\ \vdots \\ 0 \bold{v}_n^\top \bold{y}\end{bmatrix}=U\bold{0}=\bold{0}

Hence:

nullspace(A)=span({vj:σj=0})\mathrm{nullspace}(A)=\mathrm{span}(\{\bold{v}_j:\sigma_j=0\})

with dimension nrn-r.

We see that:

dim(range(A))+dim(nullspace(A))=n\mathrm{dim(range}(A))+\mathrm{dim(nullspace(}A))=n

This is also written: rank+nullity=n\mathrm{rank+nullity}=n

7.5.5 Truncated SVD

Let AK=UKSKVKA_K=U_KS_KV_K^\top where we use the KK first columns. This can be shown to be the optimal rank KK approximation of AA in the sense of:

AAKF=k=K+1rσk||A-A_K||_F=\sum_{k=K+1}^r \sigma_k

If K<r=rank(A)K<r=\mathrm{rank}(A), we incur some error: this is the truncated SVD.

The number of parameters needed to represent an M×NM \times N matrix is K(M+N+1)K (M+N+1).

Screen Shot 2023-03-26 at 19.06.33.png

Screen Shot 2023-03-26 at 19.06.39.png