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 sldim_by_eigval
Home > sltoolbox > subspace > sldim_by_eigval.m

sldim_by_eigval

PURPOSE ^

SLDIM_BY_EIGVAL Determines the dimension of principal subspace by eigenvalues

SYNOPSIS ^

function d = sldim_by_eigval(eigvals, sch, varargin)

DESCRIPTION ^

SLDIM_BY_EIGVAL Determines the dimension of principal subspace by eigenvalues

 $ Syntax $
   - d = sldim_by_eigval(eigvals)
   - d = sldim_by_eigval(eigvals, sch, ...)

 $ Arguments $
   - eigvals:      the eigenvalues (energies) of each dimension given in
                   descending order
   - sch:          the name of scheme of dimension evaluation, or a
                   function handle to some user-supplied functions, which
                   takes the list of eigenvalues as the first argument.

 $ Description $
   - d = sldim_by_eigval(eigvals) determines the dimension of the
     principal subspace according to eigenvalues in default way:
     'rank', i.e. set the dimension to the rank.

   - d = sldim_by_eigval(eigvals, sch, ...) determines the dimension of
     the principal subspace according to eigenvalues using a specified
     scheme. The additional arguments for the parameters for the scheme.  
     \*
     \t    Table 1. The available schemes of dimension evaluation \\
     \h      name    &          description                  \\
            'rank'   &  The dimension is determined up to the rank
                        implied by the eigenvalues. In detail, d is
                        the number of eigenvalues larger than the
                        eps(max(eigvals))  \\
            'ratio'  &  The dimension is determined by the number of
                        eigenvalues that is larger than r * max(eigvals).
                        Here r is given as the first scheme argument. \\
            'energy' &  The dimension is determined by the smallest number
                        of leading eigenvalues, so that the ratio of their 
                        sum (i.e. the energy preserved in the principal 
                        subspace) to the total sum is not less than r,
                        which is given as the first scheme argument. \\
     \*

 $ Remarks $
   - It is a required condition that the eigenvalues are not non-negative
     and sorted in descending order.
                        
 $ History $
   - Created by Dahua Lin on Apr 25, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
This function is called by:
  • slgda SLGDA Performs Baudat's Generalized Discriminant Analysis
  • slkfd SLKFD Perform Kernelized Fisher Discriminant Analysis
  • slkpca SLPCA Learns a Kernel PCA model from training samples
  • slcovpca SLCOVPCA Trains a PCA with the covariance matrix given
  • slfld SLFLD Performs Fisher Linear Discriminant Analysis
  • slnlda SLNLDA Performs Nullspace-based Linear Discriminant Analysis
  • slpca SLPCA Learns a PCA model from training samples
  • slrangespace SLRANGESPACE Determines the subspace of the range of X

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function d = sldim_by_eigval(eigvals, sch, varargin)
0002 %SLDIM_BY_EIGVAL Determines the dimension of principal subspace by eigenvalues
0003 %
0004 % $ Syntax $
0005 %   - d = sldim_by_eigval(eigvals)
0006 %   - d = sldim_by_eigval(eigvals, sch, ...)
0007 %
0008 % $ Arguments $
0009 %   - eigvals:      the eigenvalues (energies) of each dimension given in
0010 %                   descending order
0011 %   - sch:          the name of scheme of dimension evaluation, or a
0012 %                   function handle to some user-supplied functions, which
0013 %                   takes the list of eigenvalues as the first argument.
0014 %
0015 % $ Description $
0016 %   - d = sldim_by_eigval(eigvals) determines the dimension of the
0017 %     principal subspace according to eigenvalues in default way:
0018 %     'rank', i.e. set the dimension to the rank.
0019 %
0020 %   - d = sldim_by_eigval(eigvals, sch, ...) determines the dimension of
0021 %     the principal subspace according to eigenvalues using a specified
0022 %     scheme. The additional arguments for the parameters for the scheme.
0023 %     \*
0024 %     \t    Table 1. The available schemes of dimension evaluation \\
0025 %     \h      name    &          description                  \\
0026 %            'rank'   &  The dimension is determined up to the rank
0027 %                        implied by the eigenvalues. In detail, d is
0028 %                        the number of eigenvalues larger than the
0029 %                        eps(max(eigvals))  \\
0030 %            'ratio'  &  The dimension is determined by the number of
0031 %                        eigenvalues that is larger than r * max(eigvals).
0032 %                        Here r is given as the first scheme argument. \\
0033 %            'energy' &  The dimension is determined by the smallest number
0034 %                        of leading eigenvalues, so that the ratio of their
0035 %                        sum (i.e. the energy preserved in the principal
0036 %                        subspace) to the total sum is not less than r,
0037 %                        which is given as the first scheme argument. \\
0038 %     \*
0039 %
0040 % $ Remarks $
0041 %   - It is a required condition that the eigenvalues are not non-negative
0042 %     and sorted in descending order.
0043 %
0044 % $ History $
0045 %   - Created by Dahua Lin on Apr 25, 2006
0046 %
0047 
0048 
0049 %% parse and verify input arguments
0050 
0051 if nargin < 2
0052     sch = 'rank';
0053 end
0054 
0055 % determine the function
0056 
0057 if ischar(sch)
0058     
0059     switch sch
0060         case 'rank'
0061             fh = @dim_by_rank;
0062         case 'ratio'
0063             fh = @dim_by_ratio;
0064         case 'energy'
0065             fh = @dim_by_energy;
0066         otherwise
0067             error('sltoolbox:invalidarg', ...
0068                 'Invalid scheme %s for dimension determination', sch);
0069     end
0070     
0071 elseif isa(sch, 'function_handle')
0072     fh = sch;
0073     
0074 else
0075     error('sltoolbox:invalidarg', ...
0076         'Invalid sch: it should be either the name of the scheme or the user-supplied function handle');
0077 end
0078 
0079 %% select
0080 
0081 d = fh(eigvals, varargin{:});
0082 
0083 %% The predefined selection function
0084 
0085 
0086 function k = dim_by_rank(evals)
0087 
0088 k = sum(evals > eps(evals(1)));
0089 
0090 function k = dim_by_ratio(evals, r)
0091 
0092 if (r <= 0 || r >= 1)
0093     error('r should satisfy 0 < r < 1 for preservation by eigval');
0094 end
0095 
0096 k = sum(evals > r * evals(1));
0097 
0098 function k = dim_by_energy(evals, r)
0099 
0100 if (r <= 0 || r >= 1)
0101     error('r should satisfy 0 < r < 1 for preservation by energy');
0102 end
0103 
0104 energies = cumsum(evals);
0105 k = find(energies >= r * energies(end), 1);
0106 
0107

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

Contact us at files@mathworks.com