Author: Not specified Language: matlab
Description: Not specified Timestamp: 2018-05-01 02:46:18 +0000
View raw paste Reply
%X : the data we work on (60000x784 double for the MNIST set)

% substract the mean to each column (vector)
for i.html">i = 1:size(X,2)
   X(:,i.html">i) = X(:,i.html">i) - mean(X(:,i.html">i));
end

covX = cov(X);

%
[V,D] = eig(covX); %covX*V = V*D
Eigv = diag(D);

% Eigv is the array containing the eigenvalues (in ascended order).
% The colums of V are the corresponding eigenvectors.

Eigv = Eigv(end:-1:1);
V = V(:,end:-1:1);

% Now Eigv and V are in descending order

pc1 = X * V(:,1);
pc2 = X * V(:,2);
View raw paste Reply