A Tutorial on Singular Value Decomposition
Preface
Under some circumstance, we want to compress data to save storage space. For example, when iPhone7 was released, many were trapped in a dilemma: Should I buy a 32G iPhone without enough free space or that of 128G with a lot of storage being wasted? I had been trapped in such dilemma indeed. I still remember that I only had 8G storage totally when I was using my first Android phone. What annoyed me most was my thousands of photos. Well, I confess that I was being always a mad picture taker. I knew that there were some technique which could compress a picture through reducing pixel. However, it is not enough, because, as you know, in some arbitrary position in a picture, we can tell that the picture share the same color. An extreme Example: if we have a pure color picture, what we just need know is the RGB value and the size, then reproducing the picture is done without extra effort. What I was dreaming is done perfectly by Singular Value Decomposition(SVD).
Introduction
Before SVD, in this article, I will introduce some mathmatical concepts in the first place which cover Linear transformation and EigenVector&EigenValue. This Background knowledge is meant to make SVD straightforward. You can skip if you are familar with this knowledge.
Linear transformation
Given a matrice
But when we do this multiplication, what happens? Acutually, when we
multiply
then we have
You may have noticed that we can always get the same
As we know, we can put a vector to anywhere in space, and if we want
to calculate sum of two vectors, the simplest way is to connect the to
vector from one's head to the other's tail. Our example, we compute
Now we change
First of all, we multiply
Here, you can imagine that matrice
Exercise
, draw the picture to stretch and rotate .- Find a
matrix to rotate to and . - what if
.
EigenVector and EigenValue
EigenVector and EigenValue is an extremely important concept in linear algebra, and is commonly used everywhere including SVD we are talking today. However, many do not know how to interpret it. In fact, EigenVector and EigenValue is very easy as long as we know about what is linear transformation.
A Problem
Before start, let's take a look at a question: if we want to multiply
matrices for 1000 times, how to calculate effectively?
Intuition
Last section, we have talked that if we multiply a vector by a matrix
It turns out we can choose any vector along
We name vectors like
I won't cover how to compute these vectors and vaules and just list the answer as followed
If we do something on the equation
Exercise
- Research how to compute EigenVectors and EigenValues, then
compute
. - Think about the decisive factor affects how many EigenValues we can get.
Singular Value Decompositon
Notice that EigenVector Decomposition is applied to decompose square matrices. Is there any approach to decompose non-square matrices? The answer is a YES, and the name is Singular Value Decompositon.
Intuition
First of all, let's take a look at what SVD looks like
From the picture, we can find that matrice
Deduction
In the Linear Transformation section, we can transform a vector to
another coordinate axes. Assume you have a non-square matrice, and you
want to transform A from vectors
Recall that we can transform
We need do something to the equation in order to continue the
deduction. First we stretch matrice
Due to the fact we need calculate
Image Compression
Firstly, let's look at the process of compressing a picture, the left
picture is original grayscale image. On the right, under different
compress rate, we can see pictures after reproducing. Before compress,
the size of the picture is 1775K byte. Then the picture is almost the
same, when we compress which into 100K byte size, which means we can
save 90% storage space
To compress a piture, you just decompose the matrice through SVD,
then instead of using the original
1 | %% octave: core code of svd compressions |
Summary
Today we have learned mathmatics backgroud on SVD, including linear transformation and EigenVector&EigenVaule. Before SVD, we first talked about EigenValue Decomposition. Finally, Singular Vaule Decomposition is very easy to be deduced. In the last section, we took an example see how SVD be applied to image compression field.
Now, it comes to the topic how to save our storage of a 32G iPhone7, the coclusion is obvious: using SVD compress image to shrink the size of our photos.
Reference
- https://www.youtube.com/watch?v=EokL7E6o1AE
- https://www.youtube.com/watch?v=cOUTpqlX-Xs
- https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw
- https://yhatt.github.io/marp/
- https://itunes.apple.com/cn/itunes-u/linear-algebra/id354869137
- http://www.ams.org/samplings/feature-column/fcarc-svd
- https://www.cnblogs.com/LeftNotEasy/archive/2011/01/19/svd-and-applications.html