annotate toolboxes/FullBNT-1.0.7/KPMtools/pca_netlab.m @ 0:e9a9cd732c1e tip

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