Professional Documents
Culture Documents
April 6, 2009
Xin Li
PCA from SVD Principal components PCA and SVD in Matlab Application to face recognition
Xin Li
Xin Li
Xin Li
Xin Li
nn
VT
nn
= U
mn
Xin Li
nn
VT
nn
= U
mn
Xin Li
Xin Li
Xin Li
Xin Li
Xvi = i ui
Xin Li
Xin Li
Xin Li
Xin Li
Xin Li
Xin Li
Xin Li
Xin Li
Xin Li
Finally, to make the ui matrix a square matrix, we extend it an orthogonal basis: u1 , u2 , ..., um .
Xin Li
Finally, to make the ui matrix a square matrix, we extend it an orthogonal basis: u1 , u2 , ..., um . . Dene U := [u1 u2 um ] and ll 0s under [D . r (nr ) ]: .0 X=U . D . r (nr ) .0 0mr n VT
Xin Li
Finally, to make the ui matrix a square matrix, we extend it an orthogonal basis: u1 , u2 , ..., um . . Dene U := [u1 u2 um ] and ll 0s under [D . r (nr ) ]: .0 X=U We are done! . D . r (nr ) .0 0mr n VT
Xin Li
Xin Li
Xin Li
So, X = [1 u1 r ur 0 0]
Xin Li
T v1 T v2 . . .
=
r
i ui viT
i=1
Dimension reduction
Assume we have a collection data of column vectors a1 , a2 , ..., am of Rn .
Xin Li
Dimension reduction
Assume we have a collection data of column vectors a1 , a2 , ..., am of Rn . When n is large, we want reduce the dimension the data.
Xin Li
Dimension reduction
Assume we have a collection data of column vectors a1 , a2 , ..., am of Rn . When n is large, we want reduce the dimension the data. How could this be possible?
Xin Li
Dimension reduction
Assume we have a collection data of column vectors a1 , a2 , ..., am of Rn . When n is large, we want reduce the dimension the data. How could this be possible? This is possible in the case that all data vectors are actually coming from a subspace U of small dimension (say, r ).
Xin Li
Dimension reduction
Assume we have a collection data of column vectors a1 , a2 , ..., am of Rn . When n is large, we want reduce the dimension the data. How could this be possible? This is possible in the case that all data vectors are actually coming from a subspace U of small dimension (say, r ). Find an orthogonal set of vectors u1 , ... , ur that forms a basis for U!
Xin Li
Dimension reduction
Assume we have a collection data of column vectors a1 , a2 , ..., am of Rn . When n is large, we want reduce the dimension the data. How could this be possible? This is possible in the case that all data vectors are actually coming from a subspace U of small dimension (say, r ). Find an orthogonal set of vectors u1 , ... , ur that forms a basis for U! If we can do so, then ai = fi1 u1 + fi2 u2 + + fir ur , i = 1 : m for some coecients fij s.
Xin Li
Dimension reduction
Assume we have a collection data of column vectors a1 , a2 , ..., am of Rn . When n is large, we want reduce the dimension the data. How could this be possible? This is possible in the case that all data vectors are actually coming from a subspace U of small dimension (say, r ). Find an orthogonal set of vectors u1 , ... , ur that forms a basis for U! If we can do so, then ai = fi1 u1 + fi2 u2 + + fir ur , i = 1 : m for some coecients fij s. Note that fij = aT uj , the projection of ai along the direction i of uj .
Xin Li From SVD to PCA
Xin Li
max
w =1 i=1
|aT w|2 i
Xin Li
max
w =1 i=1
|aT w|2 i
Note that
|aT w|2 = AT w i
i=1 T
Xin Li
max
w =1 i=1
|aT w|2 i
Note that
|aT w|2 = AT w i
i=1 T
max
w =1 i=1
w =0
wT (AAT )w wT w
Xin Li
Xin Li
Xin Li
Let x := UT w and notice that there are only r non-zero entries 1 , ..., r in D.
Xin Li
Let x := UT w and notice that there are only r non-zero entries 1 , ..., r in D. We have
2 2 2 wT (AAT )w 2 x 2 + 2 x2 + r xr2 = 1 1 2 2 2 wT w x1 + x2 + + x m
Xin Li From SVD to PCA
Finally...
We have max
w =0 2 2 2 2 x 2 + 2 x2 + r xr2 wT (AAT )w = max 1 1 2 2 2 x=0 wT w x1 + x 2 + + xm
Xin Li
Finally...
We have max
w =0 2 2 2 2 x 2 + 2 x2 + r xr2 wT (AAT )w = max 1 1 2 2 2 x=0 wT w x1 + x 2 + + xm
Xin Li
Finally...
We have max
w =0 2 2 2 2 x 2 + 2 x2 + r xr2 wT (AAT )w = max 1 1 2 2 2 x=0 wT w x1 + x 2 + + xm
This is the largest eigenvalue of A. A vector x that makes the maximum is x1 = 1 and xi = 0 for i =2:m
Xin Li
Finally...
We have max
w =0 2 2 2 2 x 2 + 2 x2 + r xr2 wT (AAT )w = max 1 1 2 2 2 x=0 wT w x1 + x 2 + + xm
This is the largest eigenvalue of A. A vector x that makes the maximum is x1 = 1 and xi = 0 for i =2:m This corresponds to w = Ux = u1 .
Xin Li
Finally...
We have max
w =0 2 2 2 2 x 2 + 2 x2 + r xr2 wT (AAT )w = max 1 1 2 2 2 x=0 wT w x1 + x 2 + + xm
This is the largest eigenvalue of A. A vector x that makes the maximum is x1 = 1 and xi = 0 for i =2:m This corresponds to w = Ux = u1 . So, the rst principal component is indeed achieved by the rst eigenvector u1 of AAT
Xin Li From SVD to PCA
max
|aT w|2 i
i=1
Xin Li
max
|aT w|2 i
i=1
max
2 2 2 2 2 1 x1 + 2 x2 + r xr2 2 = 2 = 2 2 + x2 + + x2 x=0,x1 =0 x1 m 2
max
Xin Li
Xin Li
A vector x that makes the maximum is x2 = 1 and xi = 0 for i = 1, 3 : m This corresponds to w = Ux = u2 . So, the second principal component is indeed achieved by the second eigenvector u2 of AAT .
Xin Li
A vector x that makes the maximum is x2 = 1 and xi = 0 for i = 1, 3 : m This corresponds to w = Ux = u2 . So, the second principal component is indeed achieved by the second eigenvector u2 of AAT . Now you see the pattern: ui is the ith principal component.
Xin Li
Sample code
Let us randomly choose 20 points on a line in space (3-dimension).
Xin Li
Sample code
Let us randomly choose 20 points on a line in space (3-dimension). p=100;r=rand(1,p);x=2*r-1;y=r+2;z=3-r; scatter3(x,y,z,3*ones(1,p),1:p);colorbar;view(-30,10);
Xin Li
Sample code
Let us randomly choose 20 points on a line in space (3-dimension). p=100;r=rand(1,p);x=2*r-1;y=r+2;z=3-r; scatter3(x,y,z,3*ones(1,p),1:p);colorbar;view(-30,10); We want to nd the rst principal component.
Xin Li
Sample code
Let us randomly choose 20 points on a line in space (3-dimension). p=100;r=rand(1,p);x=2*r-1;y=r+2;z=3-r; scatter3(x,y,z,3*ones(1,p),1:p);colorbar;view(-30,10); We want to nd the rst principal component. First, we center the data by remove the mean of all points.
Xin Li
Sample code
Let us randomly choose 20 points on a line in space (3-dimension). p=100;r=rand(1,p);x=2*r-1;y=r+2;z=3-r; scatter3(x,y,z,3*ones(1,p),1:p);colorbar;view(-30,10); We want to nd the rst principal component. First, we center the data by remove the mean of all points. x=x-mean(x);y=y-mean(y);z=z-mean(z);hold on;scatter3(x,y,z,3*ones(1,p),1:p);
Xin Li
Sample code
Let us randomly choose 20 points on a line in space (3-dimension). p=100;r=rand(1,p);x=2*r-1;y=r+2;z=3-r; scatter3(x,y,z,3*ones(1,p),1:p);colorbar;view(-30,10); We want to nd the rst principal component. First, we center the data by remove the mean of all points. x=x-mean(x);y=y-mean(y);z=z-mean(z);hold on;scatter3(x,y,z,3*ones(1,p),1:p); Now, we use PCA to nd the principal direction of these points
Xin Li
Sample code
Let us randomly choose 20 points on a line in space (3-dimension). p=100;r=rand(1,p);x=2*r-1;y=r+2;z=3-r; scatter3(x,y,z,3*ones(1,p),1:p);colorbar;view(-30,10); We want to nd the rst principal component. First, we center the data by remove the mean of all points. x=x-mean(x);y=y-mean(y);z=z-mean(z);hold on;scatter3(x,y,z,3*ones(1,p),1:p); Now, we use PCA to nd the principal direction of these points A=[x;y;z];[U,S,V]=svds(A);scatter3(x,y,z,3*ones(1,p),U(:,1)*A);
Xin Li
Sample code
Let us randomly choose 20 points on a line in space (3-dimension). p=100;r=rand(1,p);x=2*r-1;y=r+2;z=3-r; scatter3(x,y,z,3*ones(1,p),1:p);colorbar;view(-30,10); We want to nd the rst principal component. First, we center the data by remove the mean of all points. x=x-mean(x);y=y-mean(y);z=z-mean(z);hold on;scatter3(x,y,z,3*ones(1,p),1:p); Now, we use PCA to nd the principal direction of these points A=[x;y;z];[U,S,V]=svds(A);scatter3(x,y,z,3*ones(1,p),U(:,1)*A); Color is according to x-projection
Xin Li From SVD to PCA
Xin Li
Xin Li
Xin Li
Xin Li
Xin Li