function [V,D]=eigpca(X)
  
% Calculate e-vecs of the covariance matrix X*X'
%  
% This procedure computes the e-vecs without defining the covariance matrix in the
% high-dimensional space. 
% 
% X(dimdata,NumDataPoints) is the data vector with each datapoint a column vector
%
% David Barber 2002
  
[d,numdata] = size(X);

if numdata<d

  [V2,D]=eig(X'*X); % find the e-vecs in the lower dimensional space
  V=(X*V2)*inv(D);

else

  [V,D]=eig(X*X'); % this is the standard approach

end

%% these are the eigenvectors of X*X' : check :
%mean(mean(abs(X*(X'*V) - V*D)))
