annotate _FullBNT/KPMtools/pca_netlab.m @ 9:4ea6619cb3f5 tip

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