Author: Not specified Language: matlab
Description: Not specified Timestamp: 2018-05-01 02:45:41 +0000
View raw paste Reply
  1. %X : the data we work on (60000x784 double for the MNIST set)
  2.  
  3. % substract the mean to each column (vector)
  4. for i.html">i = 1:size(X,2)
  5.    X(:,i.html">i) = X(:,i.html">i) - mean(X(:,i.html">i));
  6. end
  7.  
  8. covX = cov(X);
  9.  
  10. %
  11. [V,D] = eig(covX); %covX*V = V*D
  12. Eigv = diag(D);
  13.  
  14. % Eigv is the array containing the eigenvalues (in ascended order).
  15. % The colums of V are the corresponding eigenvectors.
  16.  
  17. Eigv = Eigv(end:-1:1);
  18. V = V(:,end:-1:1);
  19.  
  20. % Now Eigv and V are in descending order
  21.  
  22. pc1 = X * V(:,1);
  23. pc2 = X * V(:,2);
View raw paste Reply