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