PCA with strange reconstuction
- From: "Alessandro Crimi" <sun@xxxxxxxxxxx>
- Date: Tue, 18 Mar 2008 13:28:01 +0000 (UTC)
I have a strange behavior with a PCA code I wrote.
In practice, what I have done is - given some data -
compute the mean and the covariance matrix. From the
covariance matrix I obtained the eigenvalues and the
eigenvectors, then I reorded in descending order the
eigenvalues and eigenvector, If I use the entire set of
eigenvectors there are no problem during the projection and
the reconstruction. If I reduce the dimension of the used
eigenvectors and then try to reconstruct the reconstructed
values ARE TOTALLY WRONG. I expected that the result will
contain some errors, but the values are totally far from the
original, here is the code:
% num_used_eigenvectors is the number of used eigenvectors
[eigenvectors, eigenvalues] = eig(Covariance);
[eigenvalues,ind ] = sort(diag(eigenvalues),'descend');
descending_eigenvalues =
diag(eigenvalues(1:num_used_eigenvectors))
descending_eigenvectors = eigenvectors(:,ind);
%Project into the eigenspace
%descending_eigenvectors(:,1:num_used_eigenvectors)
%projected_data = ( points - ones(size(points,1),1)*
meanvalue ) *
descending_eigenvectors(:,1:num_used_eigenvectors);
%Reconstruct the values
reconstructed = projected_data * (
descending_eigenvectors(:,1:num_used_eigenvectors))' + meanvalue
Regards
Alex
.
- Prev by Date: Problem with GUI multiline edit object and large string
- Next by Date: Re: How to define a matrix function in M.file?
- Previous by thread: Problem with GUI multiline edit object and large string
- Next by thread: THERE IS ERROR
- Index(es):