|
• Data preprocessing with Principal Component Analysis (Emotion Classification with NNs - MATLAB)
First of all I'd like to say hello to everyone who participates in this Forum. I'm new in this Forum but I hope to get "old" soon!
Well, my question now. For the time being I'm involved in a AI Project and I experiment in backpropagation with Matlab 6.1. What I do is facial emotion recognition from a dataset of 15 individuals, I have personally obtained (each one has been photographed twice for each of the emotions "angry" "happy" "neutral" and "sad").
My main concern,for now, is the preprocessing of the data. Matlab documentation says that in order to do batch processing I have to create a matrix (for train) in which each column corresponds to one pattern (image in my case of 30x32 pixels). So the matrix for a training set of 80 images would be a 960(rows)x80(columns). Is this ok so far?
Next step is preprocessing. The problem is that if I use the function premnmx, which scales from -1 to 1, then matlab scales the graylevels at each row of the train-matrix!! What I mean if my matrix is mat=[ 1 2 3; 3 2 5; 1 1 0;9 2 3] then premnmx(mat)=[-1 0 1; -0.33 -1 1; 1 1 -1; 1 -1 -0.7143]. But if I scale from -1 to 1 each image-column I will get [-1 1 0.2; -0.5 1 1; -1 -1 -1;1 1 0.2]. Which preprocessing scalling do I need to use and why? In my case where I have column=images I saw that when I scale with the second way and plot with function "imagesc()", the image remains(correctly?) the same. However, when I scale with matlab's row-wise(first method I descibed) way I take a plot of the image that is not the same as the original(seems to be a distorted version of the original)!!! Common sense says that The second way is not going to be better..because I say that some information was lost from the image before feeding it in my NN!
I have excactly the same wonder , when I use the prestd function for normalizing the data to mean=0 and std=1. Matlab's function normalizes so as each row of my train-matrix has mean=0 and std=1. The other way is to normalize so that each column (hence each image's total pixels) has mean=0 and std=1. Once more, what method to use and why!...And to be honest..does it matter?(I gave an answer to this before..for premnmx...though not sure yet)
And finally I'm coming to the Subject of my post: Principal Component Analysis! Suppose we have a train-matrix of 80 images, hence 80x960 matrix. When I use prepca( I previously used prestd) matlab complains that rows are more than columns. Searching deeper in PCA I found that Matlab uses Singular Value Decomposition in order to find the Principal Components. But SVD( trainmat=U*S*V') will give a matrix S->960x80 with singular values(if I use svd(trainmat) and not svd(trainmat,0)!). But this matrix which is not rectangular will have only 80 non-zero values in the leading "diagonal". U would be 960x960 and V would be 80x80! Then the Transformation matrix (which keeps the eigenvector row-wise) is obtained TransMat=U' , which is a 960x960 matrix. Then, if ,for example, I decide to keep only the first 300 more important pixels(the ones that contribute more one the total variance) I cut the last 960-300=660 colums=eigenvectors in the 960x960 transormation matrx...hence my final Transformation matrix is 300x960. Finally, I project all my 80 initial images into the new 300-Dimenional space by simply multiplying PC=TransMat*trainmat, where PC are the projections-called Principal Components!....Yeah..alright.. but this only in papers! The problem is that when Matlab's prepca comes to decide how many important-pixels is going to keep it uses the singular values from matrix S which are only 80 non-zero singular values. From these 80 non-zero (in leading diagonal of S) singular values then obtains the eigenvalues=variances and compares with a min_frac to see how many eigenvalues are important and correspondigly how many eigenvectors to keep. But by doing this the maximum we can get is 80 eigenvectors(the same number as the number of patterns=images), since singular values are only 80(non-zero). What I mean is that after trainmat=U*S*V' (SVD) I get a 80x960 U matrix (as I said 80= maximum).And finally a prepca(trainmat) will give a final matrix of 80x80 (80 images=patterns=columns ,80 more important pixels=rows).
I've really stuck on this! And I can't find an other way to get a final matrix (after PCA) with more pixels than the number of patterns=images!!!!!!
When I use the following technique I get other results than the technique with SVD..why??:
trainmat=960x80.
Find the covariance matrix C (dimensionality=#pixels=960 which is going to be 960x960. Call [eigvec,eigval] = eig(C) and do eigendecomposition of C. So get the 960 eigenvalues and the 960 eigenvectors. Reorder eigenvalues from larger to smaller and do accordingly with eigenvectors, hence obtain eigvec_ordered. Take the first 300, for example, more important eigenvectors! Compose TransMat=eigvec_ordered(:,1:300)', which is a 300x960 matrix. Multiply PC=TransMat*trainmat I get a 300x80 matrix which says that I have 80 patterns each with 300 more important pixels!..yeah but this obtains different TransMat than when using SVD, and I'm talking when in both cases we choose to keep the first 80 more important pixels!!!....
To be honest either I scale/standarise column-wisely or row-wisely I get quite the same accuracy (in my NN 60-70% for emotion recognition). But I can't understand what is the difference. Additionally I want some help in PCA. I suspect that Matlab's prepca was designed for preprocessing when the patterns well outnumber the dimensions (in my case patterns are only 80 and dimension=960=pixels).
Thanks before hand for any help,
onegin
|