1

I have computed PCA using the following :

function [signals,V] = pca2(data) 
[M,N] = size(data); 
data = reshape(data, M*N,1);
% subtract off the mean for each dimension 
mn = mean(data,2); 
data = bsxfun(@minus, data, mean(data,1));     
% construct the matrix Y 
Y = data'*data / (M*N-1); 
[V D] = eigs(Y, 10);   % reduce to 10 dimension
% project the original data 
signals = data * V;

My question is:

Is "signals" is the projection of the training set into the eigenspace?

I saw in "Amir Hossein" code that "centered image vectors" that is "data" in the above code needs to be projected into the "facespace" by multiplying in the eigenspace basis's. I don't really understand why is the projection done using centered image vectors? Isn't "signals" enough for classification??

phyrox
  • 2,423
  • 15
  • 23
Sid
  • 249
  • 5
  • 16
  • are each of your faces stored as a row or a column in your "data" matrix? Your reshape in the 3rd line appears wrong in either case. And perhaps show us the code for "pca2". I suspect that "signals" is the projected version of your code but I'm not sure. Get back to me and I can help you better. FYI, you may find this [tutorial](http://www.snl.salk.edu/~shlens/pca.pdf‎) useful for understanding PCA, and indirectly how the eigenfaces technique work. – lightalchemist Jan 31 '14 at 09:50
  • @lightalchemist: the above code is for 'pca2', Its the name of the function i use for finding PCA. I am using it like this- http://stackoverflow.com/questions/21474331/why-is-the-accuracy-coming-as-0-matlab-libsvm?noredirect=1#comment32413403_21474331 – Sid Jan 31 '14 at 10:19
  • @lightalchemist : The link you have given to the tutorial shows a 404 error! Now that you told me i have to have only one eigenspace , How do i go about labeling the projections from face 1 (class +1) and other faces (class -1)?http://stackoverflow.com/questions/21426842/how-to-label-the-training-projections-obtained-by-pca-to-use-for-training-svm-fo/21446599?noredirect=1#21446599 – Sid Jan 31 '14 at 10:21
  • 1
    This link should work: [tutorial](http://www.snl.salk.edu/~shlens/pca.pdf) – lightalchemist Jan 31 '14 at 15:56
  • 1
    Look, you compute a SINGLE projection matrix from the leading eigenvectors of the covariance matrix from all your samples. Then multiply each sample (after they have the mean vector subtracted) with this projection matrix to get its new representation. These projected versions of your samples will now represent your faces. If a face has label/class) 1, then its projected sample will take the same label/class. For details as to why mean-centering is necessary and why PCA works, look at the tutorial I provided above. – lightalchemist Feb 01 '14 at 14:06
  • @lighalchemist: Thank you the tutorial is helpful. Should i do something like this ? http://stackoverflow.com/questions/21474331/why-is-the-accuracy-coming-as-0-matlab-libsvm – Sid Feb 02 '14 at 06:14

1 Answers1

1

By signals, I assume you mean to ask why are we subtracting the mean from raw vector form of image.

If you think about PCA; it is trying to give you best direction where the data varies most. However, as your images contain pixel probably only positive values those pixels will always be on positive which will mislead, especially, your first and most important eigenvector. You can search more about second moment matrix. But I will share a bad paint image that explains it. Sorry about my drawing.

Please ignore the size of stars;

Stars: Your data

Red Line: Eigenvectors;

As you can easily see in 2D, centering the data can give better direction for your principal component. If you skip this step, your first eigenvector will bias on mean and cause poorer results.

enter image description here

Semih Korkmaz
  • 1,125
  • 13
  • 26