# Cleve's Cubicle

(Difference between revisions)
 Revision as of 17:08, 17 October 2017 (edit) (Undo revision 3126 by Ranjelin (Talk))← Previous diff Revision as of 17:46, 17 October 2017 (edit) (undo)Next diff → Line 3: Line 3: SVD meets PCA, by Cleve Moler SVD meets PCA, by Cleve Moler - [https://www.mathworks.com/company/newsletters/articles/professor-svd.html MATLAB News & Notes, 2006, Cleve’s Corner] + “''The Wikipedia pages on SVD and PCA are quite good and contain a number of useful links, although not to each other.''” - +
[https://www.mathworks.com/company/newsletters/articles/professor-svd.html [itex]-[/itex]MATLAB News & Notes, Cleve’s Corner, 2006] -
-                                                                                                    quite good and contain a number of useful links,                                                                       +
-                                                                                                    although not to each other.”
+

Line 14:                                                                                                                                                                                                                    Line 11:
A = randn(m,n);                                                                                                                                                                        A = randn(m,n);

-                                                                                                    [coef,score,latent] = pca(A);                                                                                          +                                                               [coef,score,latent] = pca(A)

X       = A - mean(A);                                                                                                                                                                 X       = A - mean(A);
[U,S,V] = svd(X,'econ');                                                                                                                                                               [U,S,V] = svd(X,'econ');

-                                                                                                    % U  vs. score                                                                                                         +                                                               % S  vs. latent
rho   = rank(X);                                                                                                                                                                       rho   = rank(X);
+                                                               latent = diag(S(:,1:rho)).^2/(m-1)
+
+                                                               % U  vs. score
sense = sign(score).*sign(U*S(:,1:rho));  %account for negated left singular vector                                                                                                    sense = sign(score).*sign(U*S(:,1:rho));  %account for negated left singular vector
-                                                                                                    sum(sum(abs(score - U*S(:,1:rho).*sense)))                                                                             +                                                               score = U*S(:,1:rho).*sense
-                                                                                                    % S  vs. latent                                                                                                        +
-                                                                                                    sum(abs(latent - diag(S(:,1:rho)).^2/(m-1)))                                                                           +
% V  vs. coef                                                                                                                                                                          % V  vs. coef
sense2 = sign(coef).*sign(V(:,1:rho));    %account for corresponding negated right singular vector                                                                                     sense2 = sign(coef).*sign(V(:,1:rho));    %account for corresponding negated right singular vector
-                                                                                                    sum(sum(abs(coef - V(:,1:rho).*sense2)))                                                                               +                                                               coef = V(:,1:rho).*sense2

## Revision as of 17:46, 17 October 2017

Singular Value Decomposition versus Principal Component Analysis

SVD meets PCA, by Cleve Moler

The Wikipedia pages on SVD and PCA are quite good and contain a number of useful links, although not to each other. $LaTeX: -$MATLAB News & Notes, Cleve’s Corner, 2006

```%relationship of pca to svd
m=3;  n=7;
A = randn(m,n);

[coef,score,latent] = pca(A)

X       = A - mean(A);
[U,S,V] = svd(X,'econ');

% S  vs. latent
rho   = rank(X);
latent = diag(S(:,1:rho)).^2/(m-1)

% U  vs. score
sense = sign(score).*sign(U*S(:,1:rho));  %account for negated left singular vector
score = U*S(:,1:rho).*sense

% V  vs. coef
sense2 = sign(coef).*sign(V(:,1:rho));    %account for corresponding negated right singular vector
coef = V(:,1:rho).*sense2
```