Mercurial > hg > camir-ismir2012
comparison toolboxes/FullBNT-1.0.7/KPMtools/pca_kpm.m @ 0:cc4b1211e677 tip
initial commit to HG from
Changeset:
646 (e263d8a21543) added further path and more save "camirversion.m"
author | Daniel Wolff |
---|---|
date | Fri, 19 Aug 2016 13:07:06 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cc4b1211e677 |
---|---|
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 |