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

slgda

PURPOSE ^

SLGDA Performs Baudat's Generalized Discriminant Analysis

SYNOPSIS ^

function A = slgda(K, nums, sol)

DESCRIPTION ^

SLGDA Performs Baudat's Generalized Discriminant Analysis

 $ Syntax $
   - A = slgda(K, nums)
   - A = slgda(K, nums, sol)

 $ Arguments $
   - K:        the kernel gram matrix
   - nums:     the numbers of samples in each classes
   - sol:      the cell containing the parameter for generalized eigen
               decomposition
   - A:        the resulting projection coefficient matrix

 $ Description $
   - A = slgda(K, nums) performs Generalized Discriminant Analysis(GDA),
     an representative work in using kernel method to extend LDA, 
     proposed by Baudat et al. The generalized eigen-problem is
     solved in a default way by slsymgeig.

   - A = slgda(K, nums, sol) in the function, slsymgeig will be invoked 
     to solve the generalized eigen-decomposition problem. sol is 
     a cell containing the parameters for slsymgeig. 

 $ Remarks $
   - The function follows the instructions given in the original paper
     on GDA.

   - The projection is learned after the kernel gram matrix is
     centralized.

   - The aim of the function is to give an exact implementation of 
     of representative work GDA, so it does not offer other facilities
     such as weighting and other ways of scatter computation. For higher
     flexibility, please use the function slkfd.

 $ History $ 
   - Created by Dahua Lin on May 3rd, 2005

CROSS-REFERENCE INFORMATION ^

This function calls:
  • slsymgeig SLSYMGEIG Solve the generalized eigen decomposition for symmetric matrices
  • slcenkernel SLCENKERNEL Compute the centralized kernel matrix
  • sldim_by_eigval SLDIM_BY_EIGVAL Determines the dimension of principal subspace by eigenvalues
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
  • slnums2bounds SLNUMS2BOUNDS Compute the index-boundaries from section sizes
This function is called by:

SOURCE CODE ^

0001 function A = slgda(K, nums, sol)
0002 %SLGDA Performs Baudat's Generalized Discriminant Analysis
0003 %
0004 % $ Syntax $
0005 %   - A = slgda(K, nums)
0006 %   - A = slgda(K, nums, sol)
0007 %
0008 % $ Arguments $
0009 %   - K:        the kernel gram matrix
0010 %   - nums:     the numbers of samples in each classes
0011 %   - sol:      the cell containing the parameter for generalized eigen
0012 %               decomposition
0013 %   - A:        the resulting projection coefficient matrix
0014 %
0015 % $ Description $
0016 %   - A = slgda(K, nums) performs Generalized Discriminant Analysis(GDA),
0017 %     an representative work in using kernel method to extend LDA,
0018 %     proposed by Baudat et al. The generalized eigen-problem is
0019 %     solved in a default way by slsymgeig.
0020 %
0021 %   - A = slgda(K, nums, sol) in the function, slsymgeig will be invoked
0022 %     to solve the generalized eigen-decomposition problem. sol is
0023 %     a cell containing the parameters for slsymgeig.
0024 %
0025 % $ Remarks $
0026 %   - The function follows the instructions given in the original paper
0027 %     on GDA.
0028 %
0029 %   - The projection is learned after the kernel gram matrix is
0030 %     centralized.
0031 %
0032 %   - The aim of the function is to give an exact implementation of
0033 %     of representative work GDA, so it does not offer other facilities
0034 %     such as weighting and other ways of scatter computation. For higher
0035 %     flexibility, please use the function slkfd.
0036 %
0037 % $ History $
0038 %   - Created by Dahua Lin on May 3rd, 2005
0039 %
0040 
0041 %% parse and verify input arguments
0042 
0043 if nargin < 2
0044     raise_lackinput('slkernelscatter', 2);
0045 end
0046 
0047 if ndims(K) ~= 2 || size(K, 1) ~= size(K, 2)
0048     error('sltoolbox:invaliddims', ...
0049         'The gram matrix K should be a square matrix');
0050 end
0051 
0052 M = size(K, 1);         % number of samples
0053 N = length(nums);       % number of classes
0054 if ~isequal(size(nums), [1, N])
0055     error('sltoolbox:invaliddims', ...
0056         'The nums should be a 1 x N row vector');
0057 end
0058 if sum(nums) ~= M
0059     error('sltoolbox:sizmismatch', ...
0060         'The total number in nums is inconsistent with that in K');
0061 end
0062 
0063 if nargin < 3
0064     sol = {};
0065 end
0066 
0067 %% Compute
0068 
0069 %% Centralize
0070 
0071 K = slcenkernel(K);
0072 
0073 %% Construct the eigen-problem
0074 
0075 [sp, ep] = slnums2bounds(nums);
0076 W = zeros(M, M);
0077 for i = 1 : N
0078     ni = nums(i);
0079     spi = sp(i); epi = ep(i);
0080     W(spi:epi, spi:epi) = 1 / ni;    
0081 end
0082 clear sp ep;
0083 
0084 B = K * W * K;
0085 clear W;
0086 
0087 V = K * K;
0088 
0089 %% Resolve the eigen-problem
0090 
0091 [evs, A] = slsymgeig(B, V, sol{:});
0092 d = sldim_by_eigval(evs);
0093 A = A(:, 1:d);
0094 
0095 
0096 
0097

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

Contact us at files@mathworks.com