3 %>@brief Principal Component Analysis (PCA)
10 %> Loadings are the eigenvectors of the X
's scatter matrix. The scatter matrix is defined ad X'*X, a simmetric positive definite or semi-definite
11 %> with rank <code>r <= @ref nf</code>.
13 %> Meanings of the possible outputs:
14 %> @arg @c scores: <code>[@ref no][r]</code> PCA scores (@c r is the rank of the dataset's scatter matrix).
15 %> @arg @c loadings: <code>[@ref nf][r]</code> loadings matrix.
16 %> @arg @c lambdas: <code>[r]x[1]</code> contains the eigenvalues of the scatter matrix.
18 %> Note: the loadings vectors sometimes happen to point at the opposite directions of those obtaines by MATLAB's princomp() (not really a problem).
20 %> <h3>References</h3>
21 %> [1] R. O. Duda, P. E. Hart, and D. G. Stork, Pattern Classification, 2nd ed. New York: John Wiley & Sons, 2001.
23 %> @param X [@ref no]x[@ref nf] matrix
24 %> @return <code>[loadings]</code> or <code>[loadings, scores]</code> or <code>[loadings, scores, lambdas]</code>
25 function [varargout] = princomp2(X)
30 X = data_normalize(X,
'c'); % center
33 cc = cov(X); % Covariance matrix
36 [vv, ll] =
eig_ordered(cc); % eigenvectors, eigenvalues
43 varargout = {vv, X*vv};
45 varargout = {vv, X*vv, ll};
function adjust_unitnorm(in L)
function eig_ordered(in varargin)