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 slkfd
Home > sltoolbox > kernel > slkfd.m

slkfd

PURPOSE ^

SLKFD Perform Kernelized Fisher Discriminant Analysis

SYNOPSIS ^

function A = slkfd(K, nums, varargin)

DESCRIPTION ^

SLKFD Perform Kernelized Fisher Discriminant Analysis

 $ Syntax $
   - A = slkfd(K, nums, ...)

 $ Arguments $
   - K:        the kernel gram matrix of the training samples
   - nums:     the numbers of samples in all classes
   - A:        the projection coefficient matrix 
 
 $ Description $
   - A = slkfd(K, nums, ...) performs Kernerlized Fisher discriminant 
     analysis on the samples X according to the specified properties. 
     \*
     \t   Table 1.  The properties of Fisher Discriminant Analysis   \\
     \h     name     &     description                                \\
           'sol'     &  The cell containing the arguments for solving
                        the generalized eigen-problem by slsymgeig.  
                        default = {}.                                 \\
           'dimset'  &  The cell containing the arguments for determining
                        the output feature dimension. default = {}.
                        (refer to sldim_by_eigval).                   \\
           'Sb'      &  The pre-computed kernelized between-class 
                        scattering matrix or the cell containing 
                        the arguments for computing the kernelized 
                        scatter matrix in the form {type, ...}, 
                        which is input to slkernelscatter.     \\
           'Sw'      &  The pre-computed kernelized within-class 
                        scattering matrix or the cell containing 
                        the arguments for computing the scatter 
                        matrix in the form {type, ...}, which is 
                        input to slkernelscatter.     \\
         'weights'   &  The sample weights. default = [].   \\
     \*  

 $ History $
   - Created by Dahua Lin on May 03, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
  • slsymgeig SLSYMGEIG Solve the generalized eigen decomposition for symmetric matrices
  • sldim_by_eigval SLDIM_BY_EIGVAL Determines the dimension of principal subspace by eigenvalues
  • slscatter SLSCATTER Compute the scatter matrix
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
  • slparseprops SLPARSEPROPS Parses input parameters
This function is called by:

SOURCE CODE ^

0001 function A = slkfd(K, nums, varargin)
0002 %SLKFD Perform Kernelized Fisher Discriminant Analysis
0003 %
0004 % $ Syntax $
0005 %   - A = slkfd(K, nums, ...)
0006 %
0007 % $ Arguments $
0008 %   - K:        the kernel gram matrix of the training samples
0009 %   - nums:     the numbers of samples in all classes
0010 %   - A:        the projection coefficient matrix
0011 %
0012 % $ Description $
0013 %   - A = slkfd(K, nums, ...) performs Kernerlized Fisher discriminant
0014 %     analysis on the samples X according to the specified properties.
0015 %     \*
0016 %     \t   Table 1.  The properties of Fisher Discriminant Analysis   \\
0017 %     \h     name     &     description                                \\
0018 %           'sol'     &  The cell containing the arguments for solving
0019 %                        the generalized eigen-problem by slsymgeig.
0020 %                        default = {}.                                 \\
0021 %           'dimset'  &  The cell containing the arguments for determining
0022 %                        the output feature dimension. default = {}.
0023 %                        (refer to sldim_by_eigval).                   \\
0024 %           'Sb'      &  The pre-computed kernelized between-class
0025 %                        scattering matrix or the cell containing
0026 %                        the arguments for computing the kernelized
0027 %                        scatter matrix in the form {type, ...},
0028 %                        which is input to slkernelscatter.     \\
0029 %           'Sw'      &  The pre-computed kernelized within-class
0030 %                        scattering matrix or the cell containing
0031 %                        the arguments for computing the scatter
0032 %                        matrix in the form {type, ...}, which is
0033 %                        input to slkernelscatter.     \\
0034 %         'weights'   &  The sample weights. default = [].   \\
0035 %     \*
0036 %
0037 % $ History $
0038 %   - Created by Dahua Lin on May 03, 2006
0039 %
0040 
0041 %% parse and verify input arguments
0042 
0043 if nargin < 2
0044     raise_lackinput('slkfd', 2);
0045 end
0046 
0047 % for K
0048 n = size(K, 1);
0049 if ~isequal(size(K), [n, n])
0050     error('sltoolbox:invaliddims', ...
0051         'K should be a square matrix');
0052 end
0053 
0054 % for nums
0055 nc = length(nums);
0056 if ~isequal(size(nums), [1 nc])
0057     error('sltoolbox:sizmismatch', ...
0058         'nums should be a 1 x nc row vector');
0059 end
0060 
0061 % for options
0062 
0063 opts.sol = {};
0064 opts.dimset = {};
0065 opts.Sb = {'Sb'};
0066 opts.Sw = {'Sw'};
0067 opts.weights = [];
0068 opts = slparseprops(opts, varargin{:});
0069 
0070 has_Sb = ~isempty(opts.Sb) && isnumeric(opts.Sb);
0071 has_Sw = ~isempty(opts.Sw) && isnumeric(opts.Sw);
0072 if has_Sb
0073     Sb = opts.Sb;
0074     if ~isequal(size(Sb), [n n])
0075         error('sltoolbox:sizmismatch', ...
0076             'Sb should be a n x n matrix');
0077     end
0078 end
0079 if has_Sw
0080     Sw = opts.Sw;
0081     if ~isequal(size(Sw), [n n])
0082         error('sltoolbox:sizmismatch', ...
0083             'Sw should be a n x n matrix');
0084     end
0085 end
0086 
0087 if ~isempty(opts.weights)
0088     w = opts.weights;
0089     if ~isequal(size(w), [1 n])
0090         error('sltoolbox:sizmismatch', ...
0091             'The weights should be a 1 x n row vector');
0092     end
0093 else
0094     w = [];
0095 end
0096 
0097 
0098 %% Compute
0099 
0100 %% Step 1: Construct the eigen-problem
0101 
0102 if ~has_Sb
0103     Sb = slscatter(K, opts.Sb{:}, 'sweights', w, 'nums', nums);
0104 end
0105 
0106 if ~has_Sw
0107     Sw = slscatter(K, opts.Sw{:}, 'sweights', w, 'nums', nums);
0108 end
0109 
0110 
0111 %% Step 2: Resolve the eigen-problem
0112 
0113 [evs, A] = slsymgeig(Sb, Sw, opts.sol{:});
0114 
0115 rk = sldim_by_eigval(evs, opts.dimset{:});
0116 A = A(:, 1:rk);
0117 
0118

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

Contact us at files@mathworks.com