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

slkernelfea

PURPOSE ^

SLKERNELFEA Extracts kernelized mapped features

SYNOPSIS ^

function Y = slkernelfea(X, X0, kparams, varargin)

DESCRIPTION ^

SLKERNELFEA Extracts kernelized mapped features

 $ Syntax $
   - Y = slkernelfea(X, X0, kparams)
   - Y = slkernelfea(X, X0, kparams, ...)

 $ Arguments $
   - X:            the target sample matrix.
   - X0:           the referenced sample set.
   - kparams:      the cell containing the parameters for kernel
                   computation. 
   - Y:            the feature matrix.

 $ Description $
   - Y = slkernelfea(X, X0, kparams) computes the empirical kernel maps
     for the samples X. kparams is a cell of parameters specifying
     the computation of kernels, which is given in the form:
     {kernel_type, ...} and input to slkernel function.

   - Y = slkernelfea(X, X0, kparams, ...) computes kernel mapped features
     according to the specified properties.
     \*
     \t   Table 1. Properties for Kernelized Feature Extraction \\
     \h    name    &       description                          \\
           'cen'   &  Whether to centralize the features. default = false.
                      Note that, typically if centralization is applied
                      in training stage, it should be also applied in
                      testing stage for consistency.            \\
           'proj'  &  The further projection coefficient matrix. 
                      default = []. If an non-empty projection matrix
                      is given, it will takes a further projection step.
                      The projection matrix is of size n0 x d, where n0
                      is the number of the referenced samples (i.e. the
                      dimension of empirical kernel mapping), d is the 
                      dimension of projected subspace.          \\
           'gram'  &  The gram matrix of the referenced sample set. It
                      will be used for centralization. When used, if it
                      is not specified, the function will compute it from
                      X0. However, it is more efficient to offer it
                      when it is available and centralization is 
                      required. default = []. \\
         'weights' &  The weights of referenced samples. If specified, it
                      will be used by centralization for mean feature
                      computation. default = []. \\
           'kfunc' &  The function for kernel computing. By default, it 
                      is set to empty, which indicates to use slkernel
                      for kernel computing. The user can supply its
                      owned kernel computing function, which should
                      follow the syntax as f(X0, X, ...). \\
     \*

 $ History $
   - Created by Dahua Lin on May 2nd, 2005

CROSS-REFERENCE INFORMATION ^

This function calls:
  • slcenkernel SLCENKERNEL Compute the centralized kernel matrix
  • slkernel SLKERNEL Computes the kernel for samples
  • 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 Y = slkernelfea(X, X0, kparams, varargin)
0002 %SLKERNELFEA Extracts kernelized mapped features
0003 %
0004 % $ Syntax $
0005 %   - Y = slkernelfea(X, X0, kparams)
0006 %   - Y = slkernelfea(X, X0, kparams, ...)
0007 %
0008 % $ Arguments $
0009 %   - X:            the target sample matrix.
0010 %   - X0:           the referenced sample set.
0011 %   - kparams:      the cell containing the parameters for kernel
0012 %                   computation.
0013 %   - Y:            the feature matrix.
0014 %
0015 % $ Description $
0016 %   - Y = slkernelfea(X, X0, kparams) computes the empirical kernel maps
0017 %     for the samples X. kparams is a cell of parameters specifying
0018 %     the computation of kernels, which is given in the form:
0019 %     {kernel_type, ...} and input to slkernel function.
0020 %
0021 %   - Y = slkernelfea(X, X0, kparams, ...) computes kernel mapped features
0022 %     according to the specified properties.
0023 %     \*
0024 %     \t   Table 1. Properties for Kernelized Feature Extraction \\
0025 %     \h    name    &       description                          \\
0026 %           'cen'   &  Whether to centralize the features. default = false.
0027 %                      Note that, typically if centralization is applied
0028 %                      in training stage, it should be also applied in
0029 %                      testing stage for consistency.            \\
0030 %           'proj'  &  The further projection coefficient matrix.
0031 %                      default = []. If an non-empty projection matrix
0032 %                      is given, it will takes a further projection step.
0033 %                      The projection matrix is of size n0 x d, where n0
0034 %                      is the number of the referenced samples (i.e. the
0035 %                      dimension of empirical kernel mapping), d is the
0036 %                      dimension of projected subspace.          \\
0037 %           'gram'  &  The gram matrix of the referenced sample set. It
0038 %                      will be used for centralization. When used, if it
0039 %                      is not specified, the function will compute it from
0040 %                      X0. However, it is more efficient to offer it
0041 %                      when it is available and centralization is
0042 %                      required. default = []. \\
0043 %         'weights' &  The weights of referenced samples. If specified, it
0044 %                      will be used by centralization for mean feature
0045 %                      computation. default = []. \\
0046 %           'kfunc' &  The function for kernel computing. By default, it
0047 %                      is set to empty, which indicates to use slkernel
0048 %                      for kernel computing. The user can supply its
0049 %                      owned kernel computing function, which should
0050 %                      follow the syntax as f(X0, X, ...). \\
0051 %     \*
0052 %
0053 % $ History $
0054 %   - Created by Dahua Lin on May 2nd, 2005
0055 %
0056 
0057 %% parse and verify input arguments
0058 
0059 if nargin < 3
0060     raise_lackinput('slkernelfea', 3);
0061 end
0062 
0063 % for X
0064 if ndims(X) ~= 2
0065     error('sltoolbox:invaliddims', ...
0066         'The sample matrix X should be a 2D matrix');
0067 end
0068 d = size(X, 1);
0069 
0070 % for X0
0071 if ndims(X0) ~= 2
0072     error('sltoolbox:invaliddims', ...
0073         'The sample matrix X0 should be a 2D matrix');
0074 end
0075 if size(X0, 1) ~= d
0076     error('sltoolbox:sizmismatch', ...
0077         'Size inconsistency between X and X0');
0078 end
0079 n0 = size(X0, 2);
0080 
0081 % for kparams
0082 if ~iscell(kparams)
0083     error('sltoolbox:invalidarg', ...
0084         'kernel parameters should be given by cell array');
0085 end
0086 
0087 % for options
0088 opts.cen = false;
0089 opts.proj = [];
0090 opts.gram = [];
0091 opts.kfunc = [];
0092 opts.weights = [];
0093 opts = slparseprops(opts, varargin{:});
0094 
0095 % for projection matrix
0096 if isempty(opts.proj)
0097     need_proj = false;
0098 else
0099     if ndims(opts.proj) ~= 2
0100         error('sltoolbox:invaliddims', ...
0101             'The projection coefficient matrix should be 2D');
0102     end
0103     need_proj = true;
0104     A = opts.proj;
0105     if size(A, 1) ~= n0
0106         error('sltoolbox:sizmismatch', ...
0107             'Size inconsistency between X0 and A, the projection matrix A should be an n0 x d matrix');
0108     end
0109 end
0110 
0111 % for gram matrix K0
0112 if isempty(opts.gram)
0113     has_gram = false;
0114 else
0115     has_gram = true;
0116     K0 = opts.gram;
0117     if ~isequal(size(K0), [n0, n0])
0118         error('sltoolbox:sizmismatch', ...
0119             'Invalid size of gram matrix, which should be n0 x n0');
0120     end
0121 end
0122 
0123 % for kernel computing function
0124 if ...
0125         isempty(opts.kfunc) || ...
0126         isequal(opts.kfunc, @slkernel) || ...
0127         strcmpi(opts.kfunc, 'slkernel')
0128     
0129     use_special_kfunc = false;
0130 else
0131     use_special_kfunc = true;
0132 end
0133 
0134 % for sample weights
0135 if ~isempty(opts.weights)
0136     if ~isequal(size(opts.weights), [1, n0])
0137         error('sltoolbox:sizmismatch', ...
0138             'The weights should be a 1 x n0 row vector');
0139     end
0140 end
0141 
0142 
0143 %% Compute
0144 
0145 %% Empirical Kernel Mapping
0146 
0147 if ~use_special_kfunc
0148     Kx = slkernel(X0, X, kparams{:});
0149 else
0150     Kx = feval(opts.kfunc, X0, X, kparams{:});
0151 end
0152 
0153 %% Centralization
0154 
0155 if opts.cen
0156     
0157     % compute gram matrix
0158     if ~has_gram
0159         if ~use_special_kfunc
0160             K0 = slkernel(X0, kparams{:});
0161         else
0162             K0 = feval(opts.kfunc, X0, X0, kparams{:});
0163         end                    
0164     end
0165     
0166     % centralize
0167     Kx = slcenkernel(K0, Kx, opts.weights);    
0168 end
0169 
0170 %% Projection and Output
0171 
0172 if need_proj    
0173     Y = A' * Kx;     
0174 else
0175     Y = Kx;
0176 end
0177 
0178

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

Contact us at files@mathworks.com