Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of slcovpca
Home > sltoolbox > subspace > slcovpca.m

slcovpca

PURPOSE ^

SLCOVPCA Trains a PCA with the covariance matrix given

SYNOPSIS ^

function S = slcovpca(vmean, C, preserve)

DESCRIPTION ^

SLCOVPCA Trains a PCA with the covariance matrix given

 $ Syntax $
   - S = slcovpca(vmean, C)
   - S = slcovpca(vmean, C, preserve)

 $ Arguments $
   - vmean:    the mean vector
               (set vmean to zero indicates a zero mean vector)
   - C:        the covariance matrix
   - preserve: the scheme of determinaton of the subspace dimension
               default = {'rank'}
   - S:        the struct of PCA model

 $ History $
   - Created by Dahua Lin, on Aug 17, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
  • slsymeig SLSYMEIG Compute the eigenvalues and eigenvectors for symmetric matrix
  • sldim_by_eigval SLDIM_BY_EIGVAL Determines the dimension of principal subspace by eigenvalues
This function is called by:

SOURCE CODE ^

0001 function S = slcovpca(vmean, C, preserve)
0002 %SLCOVPCA Trains a PCA with the covariance matrix given
0003 %
0004 % $ Syntax $
0005 %   - S = slcovpca(vmean, C)
0006 %   - S = slcovpca(vmean, C, preserve)
0007 %
0008 % $ Arguments $
0009 %   - vmean:    the mean vector
0010 %               (set vmean to zero indicates a zero mean vector)
0011 %   - C:        the covariance matrix
0012 %   - preserve: the scheme of determinaton of the subspace dimension
0013 %               default = {'rank'}
0014 %   - S:        the struct of PCA model
0015 %
0016 % $ History $
0017 %   - Created by Dahua Lin, on Aug 17, 2006
0018 %
0019 
0020 
0021 [evals, evecs] = slsymeig(C);
0022 
0023 evals = max(evals, 0);
0024 if nargin < 3 || isempty(preserve)
0025     k = sldim_by_eigval(evals);
0026 else
0027     k = sldim_by_eigval(evals, preserve{:});
0028 end
0029 
0030 d = size(C, 1);
0031 total_energy = sum(evals);
0032 if k < d
0033     evals = evals(1:k);
0034     evecs = evecs(:, 1:k);
0035     prin_energy = sum(evals);
0036 else
0037     prin_energy = total_energy;
0038 end
0039 
0040 
0041 S.sampledim = d;
0042 S.feadim = k;
0043 S.support = [];
0044 if isequal(vmean, 0)
0045     S.vmean = zeros(d, 1);
0046 else
0047     S.vmean = vmean;
0048 end
0049 S.P = evecs;
0050 S.eigvals = evals;
0051 S.residue = total_energy - prin_energy;
0052 S.energyratio = prin_energy / total_energy;
0053 
0054 
0055 
0056 
0057 
0058

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com