HomeVideos

SVD Visualized, Singular Value Decomposition explained | SEE Matrix , Chapter 3 #SoME2

Now Playing

SVD Visualized, Singular Value Decomposition explained | SEE Matrix , Chapter 3 #SoME2

Transcript

389 segments

0:02

SVD, singular value decomposition, is

0:05

[music] a grand finale of linear

0:07

algebra. On one hand, it combines all

0:09

important concept of the subject into

0:11

just one theorem. On the other hand,

0:14

it's extremely relevant and applicable

0:16

in the age of data science and machine

0:18

learning. This is a one matrix

0:20

decomposition that rules them all.

0:22

[music]

0:24

On surface, the SVD is saying that any

0:26

matrix, regardless of symmetry, rank,

0:29

shape, can unconditionally be decomposed

0:32

into three very special matrices.

0:34

But, there's actually an intuitive

0:36

[music] and elegant visual

0:38

interpretation underneath.

0:40

I think it would be quite cool to see

0:42

for ourselves. Don't you?

0:45

And yep, there is a catch. [music] To

0:46

truly internalize and appreciate the

0:48

theorem, a journey is required. And

0:51

hence, the previous chapters.

0:54

For example, it's good to know that

0:56

diagonal matrix stretches each axis.

0:58

[music]

1:01

While the orthogonal matrix produces a

1:03

rotation.

1:06

I highly recommend chapter two. To be

1:08

honest, if you understand spectral

1:10

decomposition, you understand 80% of

1:12

SVD.

1:14

And there are three more tiny steps we

1:16

need to take to complete the journey.

1:19

You probably noticed all the

1:20

visualization we have seen so far comes

1:23

from square matrices.

1:24

Very sneaky on my part. However, the

1:27

primary appeal of SVD is it generalizes

1:30

to rectangular matrices as well.

1:32

Therefore, we need to understand how to

1:34

visualize such things.

1:37

But firstly, what exactly is difference

1:39

between the two vectors here?

1:41

My teacher say the left one is in R2,

1:44

the right one is in R3.

1:46

I used to think those are the same

1:47

thing. I mean, they both have one for X,

1:50

two for Y, and they got nothing for Z,

1:52

right? Even if we do represent them on

1:54

graph, they look somewhat similar.

1:56

I go ahead asking the vector on the

1:58

right about Z value. It said, "Oh,

2:01

zero."

2:03

I go ask the Z value of the left vector.

2:05

It got very confused, having no idea

2:07

what a third dimension is ever like.

2:10

In addition, I can go nudge the R3

2:12

vector around such that Z value is no

2:15

longer zero. But for the R2 vector, no

2:17

matter how I rotate, stretch, scale, it

2:21

is always devoid of Z.

2:23

Despite looking similar, in reality,

2:25

they're a completely different species

2:27

that live in different dimension of the

2:29

universe.

2:30

If those two types of vector are so

2:32

different, is there a mechanism which

2:34

can transform one to the other?

2:36

And that's the power of rectangular

2:38

matrix.

2:39

In particular, a 2 by 3 matrix has the

2:42

ability to take a vector in R3,

2:45

transforming that down to a vector in

2:47

R2.

2:48

Makes quite a lot of sense if we just

2:49

look at the matrix vector

2:50

multiplication.

2:53

A matrix of size M by N has the power to

2:57

transform a vector in the nth dimension

3:00

to a vector in the mth dimension.

3:02

This is why we say matrix apply a linear

3:05

transformation from Rn to Rm.

3:09

Remember, we can represent vector as

3:11

arrow

3:12

and a represent arrow as dot

3:14

and a collection of dots as object.

3:16

Simply illustrating the visual of a

3:18

matrix is simple, but the process of

3:20

interpretation is hard. The

3:22

visualization of rectangular matrix is

3:25

very confusing. So, it's good if we try

3:27

to understand the simplest case first,

3:30

which is this matrix. You see, it's

3:32

similar to the identity matrix, but the

3:35

rectangular version of it. For the

3:36

context of this video, let's give it a

3:38

cool name, the dimension eraser.

3:41

This matrix here represent the simplest

3:43

form of linear transformation from R3 to

3:46

R2.

3:47

It's multiplication with any vector

3:49

always preserve the X and Y, but

3:52

completely remove the Z value regardless

3:54

of the initial Z. So, what this means is

3:57

that, for example, vector 1 2 1 in R3,

4:00

we can map down to vector 1 2. But, all

4:03

the vector in the form of 1 2 any Z

4:07

transforms to 1 2.

4:17

We can also have something like

4:19

dimension adder. For example, this 3 by

4:22

2 dimension adder here basically a pin

4:25

zero as a Z value for whichever input R2

4:27

vector.

4:35

Oh, actually, I think here is a good

4:37

place for me to show you a composition

4:38

from R3 to R2.

4:40

Whenever we multiply matrix and a

4:42

matrix, we essentially combine their

4:44

distinct linear transformations. Here,

4:47

we can multiply the dimension eraser

4:48

with this diagonal matrix.

4:50

[music]

4:50

And let's call this product matrix C.

4:53

The dimension eraser takes away the

4:55

third dimension.

4:57

And then diagonal matrix stretches the X

4:59

and Y axis accordingly.

5:02

The matrix C, since it's a composition

5:04

of the two matrices on the right, it

5:05

basically encapsulates the two

5:07

transformations but in just one go.

5:15

Chapter two flashback. Symmetric matrix

5:18

is a square matrix in which on two sides

5:21

of the diagonal line, the entries are

5:23

identical. It has a very strong property

5:25

which almost no other matrices have. The

5:28

eigen vectors of symmetric matrix are

5:31

perpendicular to each other. So, that

5:32

means if we normalize the eigen vectors

5:35

and package them into a matrix, we get

5:37

an orthogonal matrix which implies

5:39

rotation.

5:41

The transpose rotates the eigen vector

5:44

to align with the standard basis.

5:47

If we don't take the transpose, that

5:49

matrix rotates the standard basis to the

5:52

eigen vector.

5:54

Symmetric matrix is nice. We got to take

5:57

advantage.

5:58

Yet, everyone knows most matrices in

6:01

nature are not symmetrical.

6:03

But, we just happen to have the ability

6:05

to artificially construct symmetry out

6:08

of nowhere. Consider this matrix here,

6:11

which is obviously not symmetrical.

6:14

If we take the transpose and multiply

6:16

them together,

6:17

we get a square matrix,

6:21

but also symmetric.

6:25

We can also put the transpose on the

6:27

left and do the multiplication. We'll

6:29

once again see a square matrix

6:33

that is also symmetrical.

6:36

It's good to take a moment here to

6:37

appreciate we just created two symmetric

6:40

matrices from a rectangular matrix A.

6:43

In general, this is true for any matrix

6:46

A, which AA transpose and A transpose A

6:50

are symmetric matrices.

6:52

See if you can prove this statement on

6:53

your own.

6:55

For now, we stick to the concrete case

6:57

when A is 2 by 3.

6:59

And let's give them some meaningful

7:01

names as well.

7:02

Since they're symmetric matrices, the

7:04

letter S better be in there.

7:06

Let's call AA transpose S left

7:11

and A transpose A

7:13

S right.

7:17

I know that you know S left and S right

7:19

are symmetric matrices.

7:21

So, S left would have two perpendicular

7:24

eigen vectors in R2 and S right would

7:26

have three perpendicular eigen vectors

7:28

in R3.

7:30

Since all those eigen vectors are

7:32

closely related to the original matrix

7:34

A, we have special names for them as

7:36

well.

7:37

The eigen vector of S left are known as

7:40

the left singular vector of A. And

7:43

likewise, the eigenvectors of S right

7:47

are the right singular vectors.

7:52

Up next, I'm about to provide two facts

7:55

without going to the detail. S left and

7:57

S right are known as PSD matrices. This

8:00

implies the eigenvalue for each

8:02

eigenvector are non-negative.

8:06

The second fact, which is not obvious,

8:08

if we sort the eigenvalues in descending

8:11

order for both set, the overlap ones are

8:14

numerically identical. The biggest

8:16

eigenvalue of S left equals to the

8:18

biggest eigenvalue of S right, and so

8:21

forth.

8:25

The leftover eigenvalue is guaranteed to

8:27

be zero.

8:29

Just like the singular vectors, those

8:32

shared eigenvalues are indirectly

8:34

derived from the very original matrix A.

8:37

If we take the square root

8:39

and my friend, those are the singular

8:42

values of matrix A.

8:47

A lot of things we did so far seem

8:49

random.

8:50

We have ambiently collected all pieces

8:52

of knowledge which we need to understand

8:54

SVD.

8:56

Now behold his entrance.

8:58

Once again, any matrix A can be

9:01

unconditionally decomposed into three

9:04

very special matrices, in which the

9:07

matrix sigma is rectangularly diagonal,

9:10

the matrix V and U are orthogonal

9:13

matrices.

9:15

But what exactly are they?

9:18

The matrix sigma would have the same

9:20

dimension as matrix A. The numbers on

9:23

the diagonal are the singular values of

9:26

matrix A arranged in descending orders.

9:29

Every other entry is zero.

9:31

The matrix U contains the normalized

9:34

eigenvectors of S left, which are

9:36

arranged in descending order of their

9:39

eigen values. Another way of saying this

9:41

is matrix U contains the left singular

9:44

vectors of matrix A.

9:46

On the other hand, matrix V contains the

9:49

normalized right singular vectors of

9:51

matrix A, also arranged in descending

9:53

order. And then we transpose that to get

9:56

V transpose.

9:58

And remember, this generalizes to all

10:01

kinds of matrix A.

10:07

The moment I've been waiting for, the

10:09

visualization.

10:11

The matrix A here, by itself, applies a

10:13

complicated linear transformation from

10:15

R3 to R2.

10:18

But we know, using SVD, it can be

10:20

perfectly understood as sequentially

10:22

applying the three simple matrices on

10:24

the right.

10:25

The blue matrix, or V transpose, is an

10:28

orthogonal matrix, which applies a

10:30

rotation such that the right singular

10:33

vectors return to the standard bases.

10:35

So, more precisely, the singular vector

10:38

with biggest singular value lands on X

10:40

axis, the singular vector with the

10:42

second biggest singular value goes on

10:44

the Y axis, and so forth. [music]

10:46

The matrix sigma is rectangularly

10:49

diagonal, and it's essentially a square

10:52

diagonal matrix composed with a

10:53

dimension eraser.

10:55

The dimension eraser is removing the

10:56

third dimension.

10:58

And through that, the diagonal matrix

11:01

stretches X and Y axis based on the

11:03

singular value.

11:08

And the final step, the matrix U,

11:11

rotates the standard bases to align with

11:13

the left singular vectors.

11:16

And boy, you bet, those transformations

11:18

composed is exactly the same as A.

11:26

So, Wikipedia said a few things about

11:28

the visual flavor of SVD, that any

11:30

matrix essentially just maps sphere into

11:33

ellipsoid across different dimensions.

11:36

Let's see for ourselves.

11:37

After singular value decomposition, the

11:40

first step of any linear transformation

11:42

is always a rotation in Rn.

11:45

If you rotate a sphere, it's still a

11:47

sphere.

11:48

Taking away the third dimension of a

11:50

sphere in R3 makes it a circle in R2.

11:55

Stretching uniformly along the X and Y

11:58

axis makes a circle an ellipse.

12:02

And a final rotation still preserves the

12:04

geometry of the ellipse, just changing

12:06

that to a different position in R2.

12:10

And by no means that was any rigorous

12:12

proof, but certainly some intuitions.

12:16

And lastly, let's look at an example of

12:18

a linear transformation from R2 to R3.

12:25

The spirit of SVD very much still holds.

12:28

Firstly, we begin with the rotation in

12:29

R2.

12:30

But next, since the matrix sigma is 3 by

12:33

2, we scale based on the singular

12:35

values.

12:39

And then, we're adding a new dimension.

12:45

And finally, we rotate the standard

12:47

basis XYZ to align with the left

12:50

singular vectors.

12:54

This video should end now.

12:56

Nevertheless, it's good to contemplate

12:58

on a question.

12:59

Is the entire purpose of SVD to

13:02

decompose a linear transformation into

13:04

those four sequential actions?

13:06

Is our visualization the correct

13:09

interpretation of SVD itself?

13:12

Not exactly. I mean, what even is a

13:15

matrix to begin with?

13:17

This mathematical object has different

13:19

interpretations under different

13:21

contexts.

13:22

The same matrix can mean very different

13:24

things to different people.

13:26

Another popular interpretation of SVD is

13:29

to view a high rank matrix as a

13:31

summation of rank one matrices.

13:37

An application of this is low rank

13:38

approximation.

13:40

We can view a picture as a massive

13:42

matrix of pixels

13:43

and then gradually approximate that

13:45

picture by adding more and more rank one

13:47

matrices.

13:52

A wise man once said, "The purpose of

13:54

computing is insight, not numbers."

13:57

I think the same goes for visualizations

13:59

as well.

14:01

SVD as a math exercise is an intense

14:03

algebraic procedure to follow.

14:05

Sometimes, after three pages of matrix

14:07

multiplication and characteristic

14:09

polynomial, I understood of nothing of

14:12

what I just did.

14:14

But decompose and visualize a matrix A

14:17

into four distinct pieces of simple

14:19

transformation gives you so much more

14:21

insights than you'd otherwise have. Each

14:24

and every single step interpretable and

14:26

makes perfect sense. We know precisely

14:28

what's going on.

14:31

In particular, that very initial step of

14:33

rotation from the right singular vector

14:36

onto the standard basis actually

14:38

captures the essence of something called

14:40

principal component analysis.

14:42

I promise a video in the future.

14:46

Even when things extend beyond the three

14:48

dimension, this type of decomposition

14:50

still give us a reasonable intuition of

14:52

linear transformation on vectors,

14:54

allowing us to say about things which we

14:56

couldn't see. We know that a rotation

14:58

does not make things bigger or smaller.

15:01

Therefore, when this matrix acts on

15:03

higher dimensional object, nothing

15:04

scale, squash, blown out of proportion,

15:07

but pristine rotation around the origin.

15:10

And after that, the last two dimensions

15:12

of the object is taken away.

15:16

Sometimes learning the final theorems of

15:18

subject is like climbing a mountain. We

15:20

get a nice scenery on the top, a higher

15:22

level overview.

15:24

But, it's nice to look afar at the other

15:26

summits. And what we see is a Fourier

15:29

transform.

15:30

I just want to say some similarity they

15:32

share about the two monumental theorems

15:35

obsession with extreme generalization

15:39

and decomposition.

15:41

The Fourier transform is saying, "Any

15:43

function can be decomposed as the sum of

15:46

sinusoidal wave functions."

15:50

And then when you see the pie creature,

15:51

you already know it's a good video. I

15:52

left link here.

15:57

And thank you for watching through the

15:59

end.

Interactive Summary

This video provides an intuitive, visual explanation of Singular Value Decomposition (SVD), explaining how any matrix can be decomposed into three distinct, interpretable linear transformations: a rotation, a scaling operation (involving dimension changes), and another rotation. The narrator demystifies the complex algebraic procedure by breaking it down into manageable components and illustrating how these geometric transformations map spheres into ellipsoids, while also highlighting the connection between SVD and other concepts like Principal Component Analysis (PCA).

Suggested questions

3 ready-made prompts