Dimension reduction

7.5. Dimension reduction#

The SVD has another important property that proves very useful in a variety of applications. Let A be a real m×n matrix with SVD A=USVT and (momentarily) mn. Another way of writing the thin form of the SVD is

(7.5.1)#A=U^S^VT=[u1u2un][σ1σn][v1TvnT] =[σ1u1σnun][v1TvnT]=σ1u1v1T++σrurvrT=i=1rσiuiviT,

where r is the rank of A. The final formula also holds for the case m<n.

Each outer product uiviT is a rank-1 matrix of unit 2-norm. Thanks to the ordering of singular values, then, Equation (7.5.1) expresses A as a sum of decreasingly important contributions. This motivates the definition, for 1kr,

(7.5.2)#Ak=i=1kσiuiviT=UkSkVkT,

where Uk and Vk are the first k columns of U and V, respectively, and Sk is the upper-left k×k submatrix of S.

The rank of a sum of matrices is always less than or equal to the sum of the ranks, so Ak is a rank-k approximation to A. It turns out that Ak is the best rank-k approximation of A, as measured in the matrix 2-norm.

Theorem 7.5.1

Suppose A has rank r and let A=USVT be an SVD. Let Ak be as in (7.5.2) for 1k<r. Then

  1. AAk2=σk+1,k=1,,r1, and

  2. If the rank of B is k or less, then AB2σk+1.

Proof

Compression#

If the singular values of A decrease sufficiently rapidly, then Ak may capture the most significant behavior of the matrix for a reasonably small value of k.

Demo 7.5.2

We make an image from some text, then reload it as a matrix.

Hide code cell source
plot(annotations=(0.5,0.5,text("Hello world",44,:center,:center)),
    grid=:none,frame=:none,size=(400,150))
savefig("hello.png")
img = load("hello.png")
A = @. Float64(Gray(img))
Gray.(A)

Next we show that the singular values decrease until they reach zero (more precisely, until they are about ϵmach times the norm of the matrix) at around k=45.

U,σ,V = svd(A)
scatter(σ,xaxis=(L"i"), yaxis=(:log10,L"\sigma_i"),
    title="Singular values")
Singular values

The rapid decrease suggests that we can get fairly good low-rank approximations.

plt = plot(layout=(2,2),frame=:none,aspect_ratio=1,titlefontsize=10)
for i in 1:4
    k = 3i
    Ak = U[:,1:k]*diagm(σ[1:k])*V[:,1:k]'
    plot!(Gray.(Ak),subplot=i,title="rank = $k")
end
plt
rank = 3 rank = 6 rank = 9 rank = 12

Consider how little data is needed to reconstruct these images. For rank-9, for instance, we have 9 left and right singular vectors plus 9 singular values, for a compression ratio of better than 12:1.

m,n = size(A)
compression = m*n / (9*(m+n+1))
12.099213551119178

Exercises#

  1. ✍ Suppose that A is an n×n matrix. Explain why σn is the distance (in 2-norm) from A to the set of all singular matrices.

  2. ✍ Suppose A is a 7×4 matrix and the eigenvalues of AA are 3, 4, 7, and 10. How close is A in the 2-norm to (a) a rank-3 matrix? (b) a rank-2 matrix?

  3. (a) ⌨ Find the rank-1 matrix closest to

    A=[1551],

    as measured in the 2-norm.

    (b) ⌨ Repeat part (a) for

    A=[1501].
  4. ✍ Find the rank-1 matrix closest to

    A=[1bb1],

    as measured in the 2-norm, where b>0.

  5. ⌨ Following Demo 7.5.2 as a guide, load the “mandrill” test image and convert it to a matrix of floating-point pixel grayscale intensities. Using the SVD, display as images the best approximations of rank 5, 10, 15, and 20.


1

In statistics this quantity may be interpreted as the fraction of explained variance.