comparison toolboxes/FullBNT-1.0.7/KPMstats/pca.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 [PCcoeff, PCvec] = pca(data, N)
2 %PCA Principal Components Analysis
3 %
4 % Description
5 % PCCOEFF = PCA(DATA) computes the eigenvalues of the covariance
6 % matrix of the dataset DATA and returns them as PCCOEFF. These
7 % coefficients give the variance of DATA along the corresponding
8 % principal components.
9 %
10 % PCCOEFF = PCA(DATA, N) returns the largest N eigenvalues.
11 %
12 % [PCCOEFF, PCVEC] = PCA(DATA) returns the principal components as well
13 % as the coefficients. This is considerably more computationally
14 % demanding than just computing the eigenvalues.
15 %
16 % See also
17 % EIGDEC, GTMINIT, PPCA
18 %
19
20 % Copyright (c) Ian T Nabney (1996-2001)
21
22 if nargin == 1
23 N = size(data, 2);
24 end
25
26 if nargout == 1
27 evals_only = logical(1);
28 else
29 evals_only = logical(0);
30 end
31
32 if N ~= round(N) | N < 1 | N > size(data, 2)
33 error('Number of PCs must be integer, >0, < dim');
34 end
35
36 % Find the sorted eigenvalues of the data covariance matrix
37 if evals_only
38 PCcoeff = eigdec(cov(data), N);
39 else
40 [PCcoeff, PCvec] = eigdec(cov(data), N);
41 end
42