comparison toolboxes/FullBNT-1.0.7/KPMtools/pca_kpm.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function [pc_vec]=pca_kpm(features,N, method);
2 % PCA_KPM Compute top N principal components using eigs or svd.
3 % [pc_vec]=pca_kpm(features,N)
4 %
5 % features(:,i) is the i'th example - each COLUMN is an observation
6 % pc_vec(:,j) is the j'th basis function onto which you should project the data
7 % using pc_vec' * features
8
9 [d ncases] = size(features);
10 fm=features-repmat(mean(features,2), 1, ncases);
11
12
13 if method==1 % d*d < d*ncases
14 fprintf('pca_kpm eigs\n');
15 options.disp = 0;
16 C = cov(fm'); % d x d matrix
17 [pc_vec, evals] = eigs(C, N, 'LM', options);
18 else
19 % [U,D,V] = SVD(fm), U(:,i)=evec of fm fm', V(:,i) = evec of fm' fm
20 fprintf('pca_kpm svds\n');
21 [U,D,V] = svds(fm', N);
22 pc_vec = V;
23 end
24
25 if 0
26 X = randn(5,3);
27 X = X-repmat(mean(X),5,1);
28 C = X'*X;
29 C2=cov(X)
30 [U,D,V]=svd(X);
31 [V2,D2]=eig(X)
32 end