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

sllda

PURPOSE ^

SLLDA Trains a Linear Discriminant Model using specified method

SYNOPSIS ^

function T = sllda(X, nums, method, varargin)

DESCRIPTION ^

SLLDA Trains a Linear Discriminant Model using specified method

 $ Syntax $
   - T = sllda(X, nums, method, ...)

 $ Arguments $
   - X:        the sample matrix, with each column representing a sample
   - nums:     the numbers of samples in all classes
   - method:   the selected method for training
   - T:        the trained LDA model

 $ Description $
   - T = sllda(X, nums, method, ...) trains a LDA transform using
     specified method. It is actually a wrapper of some underlying
     LDA training functions such as slfld, sldlda, and slnlds etc,
     and provides a more friendly interface for users.
       
     \*
     \t    Table 1. The methods for LDA Training
     \h    name      &       description 
          'pinv'     & using pseudo inverse to invert to Sw
          'efm'      & using enhanced fisher model, with following params 
          'boundev'  & bounding the eigenvalues
          'regdual'  & the dual-space LDA based on simple regularization
          'pvldual'  & the dual-space LDA based on PVL
          'nlda'     & the null-space LDA
          'dlda'     & the direct LDA
     \*          

     You can specify addtional parameters to control the training
     process as follows:

     \*
     \t    Table 2. The LDA Training properties
     \h    name      &         description
           'prepca'  &  whether to perform a preceding PCA step
                        default = false, (for all methods except for dlda)
           'rvalue'  &  The r-value for whitening, typically it is the
                        minimum ratio of effective eigenvalue to the
                        largest eigenvalue. 
                        default = [], that is to leave the corresponding
                        method to decide the default value.
           'dimset'  &  the params to determine the number of output 
                        features, default = {'rank'}. 
                        You should use a cell to encompass the parameters
                        fed to sldim_by_eigval.
           'Sb'      &  The pre-computed between-class scatter matrix
                        or the cell array of params to compute Sb by
                        slscatter. default = {'Sb'}
           'Sw'      &  The pre-computed between-class scatter matrix
                        or the cell array of params to compute Sb by
                        slscatter. default = {'Sw'}
           'pdimset' &  The params to determine the range space.
                        (only for nlda and dlda, default = {}).
           'weights' &  The sample weights, default = [];
     \*

 $ History $
   - Created by Dahua Lin, on Aug 16th, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
  • sldlda SLDLDA Performs Direct Linear Discriminant Analysis
  • slfld SLFLD Performs Fisher Linear Discriminant Analysis
  • slnlda SLNLDA Performs Nullspace-based Linear Discriminant Analysis
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
  • slparseprops SLPARSEPROPS Parses input parameters
This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function T = sllda(X, nums, method, varargin)
0002 %SLLDA Trains a Linear Discriminant Model using specified method
0003 %
0004 % $ Syntax $
0005 %   - T = sllda(X, nums, method, ...)
0006 %
0007 % $ Arguments $
0008 %   - X:        the sample matrix, with each column representing a sample
0009 %   - nums:     the numbers of samples in all classes
0010 %   - method:   the selected method for training
0011 %   - T:        the trained LDA model
0012 %
0013 % $ Description $
0014 %   - T = sllda(X, nums, method, ...) trains a LDA transform using
0015 %     specified method. It is actually a wrapper of some underlying
0016 %     LDA training functions such as slfld, sldlda, and slnlds etc,
0017 %     and provides a more friendly interface for users.
0018 %
0019 %     \*
0020 %     \t    Table 1. The methods for LDA Training
0021 %     \h    name      &       description
0022 %          'pinv'     & using pseudo inverse to invert to Sw
0023 %          'efm'      & using enhanced fisher model, with following params
0024 %          'boundev'  & bounding the eigenvalues
0025 %          'regdual'  & the dual-space LDA based on simple regularization
0026 %          'pvldual'  & the dual-space LDA based on PVL
0027 %          'nlda'     & the null-space LDA
0028 %          'dlda'     & the direct LDA
0029 %     \*
0030 %
0031 %     You can specify addtional parameters to control the training
0032 %     process as follows:
0033 %
0034 %     \*
0035 %     \t    Table 2. The LDA Training properties
0036 %     \h    name      &         description
0037 %           'prepca'  &  whether to perform a preceding PCA step
0038 %                        default = false, (for all methods except for dlda)
0039 %           'rvalue'  &  The r-value for whitening, typically it is the
0040 %                        minimum ratio of effective eigenvalue to the
0041 %                        largest eigenvalue.
0042 %                        default = [], that is to leave the corresponding
0043 %                        method to decide the default value.
0044 %           'dimset'  &  the params to determine the number of output
0045 %                        features, default = {'rank'}.
0046 %                        You should use a cell to encompass the parameters
0047 %                        fed to sldim_by_eigval.
0048 %           'Sb'      &  The pre-computed between-class scatter matrix
0049 %                        or the cell array of params to compute Sb by
0050 %                        slscatter. default = {'Sb'}
0051 %           'Sw'      &  The pre-computed between-class scatter matrix
0052 %                        or the cell array of params to compute Sb by
0053 %                        slscatter. default = {'Sw'}
0054 %           'pdimset' &  The params to determine the range space.
0055 %                        (only for nlda and dlda, default = {}).
0056 %           'weights' &  The sample weights, default = [];
0057 %     \*
0058 %
0059 % $ History $
0060 %   - Created by Dahua Lin, on Aug 16th, 2006
0061 %
0062 
0063 %% parse and verify input arguments
0064 
0065 if nargin < 3
0066     raise_lackinput('sllda', 3);
0067 end
0068 
0069 opts.prepca = false;
0070 opts.rvalue = [];
0071 opts.dimset = {'rank'};
0072 opts.Sb = {'Sb'};
0073 opts.Sw = {'Sw'};
0074 opts.weights = [];
0075 opts.pdimset = {};
0076 
0077 opts = slparseprops(opts, varargin{:});
0078 
0079 %% delegate to concrete functions
0080 
0081 switch method
0082     case 'pinv'
0083         whitenopt = {'std', eps};
0084         T = delegate_fld(X, nums, opts, whitenopt);
0085     case 'efm'
0086         r = take_value(opts.rvalue, 1e-5);
0087         whitenopt = {'std', r};
0088         T = delegate_fld(X, nums, opts, whitenopt);
0089     case 'boundev'
0090         r = take_value(opts.rvalue, 1e-3);
0091         whitenopt = {'bound', r};
0092         T = delegate_fld(X, nums, opts, whitenopt);
0093     case 'regdual'
0094         r = take_value(opts.rvalue, 1e-3);
0095         whitenopt = {'reg', r};
0096         T = delegate_fld(X, nums, opts, whitenopt);
0097     case 'pvldual'
0098         r = take_value(opts.rvalue, 2e-3);
0099         whitenopt = {'gapprox', r};
0100         T = delegate_fld(X, nums, opts, whitenopt);
0101     case 'nlda'
0102         T = delegate_nlda(X, nums, opts);
0103     case 'dlda'
0104         T = delegate_dlda(X, nums, opts);
0105     otherwise
0106         error('sltoolbox:invalidarg', ...
0107             'Invalid LDA method %s', method);
0108 end
0109 
0110 
0111 %% Delegation wrapper
0112 
0113 function T = delegate_fld(X, nums, opts, whitenopt)
0114 
0115 ropts.prepca = opts.prepca;
0116 ropts.whiten = {'scheme', 'std', 'evproc', whitenopt};
0117 ropts.dimset = opts.dimset;
0118 ropts.Sb = opts.Sb;
0119 ropts.Sw = opts.Sw;
0120 ropts.weights = opts.weights;
0121 
0122 T = slfld(X, nums, ropts);
0123 
0124 
0125 function T = delegate_nlda(X, nums, opts)
0126 
0127 ropts.prepca = opts.prepca;
0128 ropts.pdimset = opts.pdimset;
0129 ropts.dimset = opts.dimset;
0130 ropts.Sb = opts.Sb;
0131 ropts.Sw = opts.Sw;
0132 ropts.weights = opts.weights;
0133 
0134 T = slnlda(X, nums, ropts);
0135 
0136 function T = delegate_dlda(X, nums, opts)
0137 
0138 ropts.pdimset = opts.pdimset;
0139 ropts.Sb = opts.Sb;
0140 ropts.Sw = opts.Sw;
0141 ropts.weights = opts.weights;
0142 
0143 T = sldlda(X, nums, ropts);
0144 
0145 
0146 %% Auxiliary function
0147 
0148 function v = take_value(v0, defaultv)
0149 
0150 if isempty(v0)
0151     v = defaultv;
0152 else
0153     v = v0;
0154 end
0155

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

Contact us at files@mathworks.com