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

slgbfe

PURPOSE ^

SLGBFE Performs Graph-based Feature Extraction Learning

SYNOPSIS ^

function T = slgbfe(X, G, Gc, dy, fm, varargin)

DESCRIPTION ^

SLGBFE Performs Graph-based Feature Extraction Learning

 $ Syntax $
   - T = slgbfe(X, G, Gc, dy, fm, ...)

 $ Arguments $
   - X:        The sample matrix 
   - G:        The graph to be optimized
   - Gc:       The constraint graph
   - dy:       The dimension of feature space
   - fm:       The formulation type
   - T:        The learned transform matrix (dx x dy)
               the transform is done by y = T' * x

 $ Description $
   - T = slgbfe(X, G, Gc, dy, fm, ...) performs graph-based feature 
     extraction learning. It is to solve the following optimization.
       
       min/max  T'X M(G) X'T,    s.t. T'X M(Gc) X'T = I

     The concrete formulation depends on the formulation type given in
     fm = {fg, fc}. For fg, it has the following three types:
       - 'minW':   do minimization with M(G) = W
       - 'maxW':   do maximization with M(G) = W
       - 'minL':   do minimization with M(G) = L = D - W
       - 'maxL':   do maximization with M(G) = L = D - W
     For fc, it has the following three types:
       - 'O':      constraint T be orthogonal: T'*T = I (ignore Gc)
       - 'I':      constraint T'* X * X' * T = I (ignore Gc)
       - 'WC':     constraint with M(Gc) = W of Gc
       - 'LC':     constraint with M(Gc) = L of Gc: D - W
     In the aforementioned formulation, W is the adjacency matrix, while
     L is the Laplacian matrix. When Gc is ignored (as in 'O' and 'I'),
     you can just input Gc as [].

     You can further specify the following properties to control the 
     learning process:
       - 'whparams':  The parameters for doing whitening of M(Gc), please
                      refer to the function slwhiten_from_cov. The params 
                      are given in a cell array as {method, ...}. 
                      default = {}
       - 'skip':      The number of components to be skipped. default = 0

 $ Remarks $
   - The implementation is based on slgembed.

   - The function will not centralize the samples, if it is needed please
     centralize them before invoking.

 $ History $
   - Created by Dahua Lin, on Sep 17, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
  • sladjmat SLADJMAT Constructs the adjacency matrix representation of a graph
  • slgraphinfo SLGRAPHINFO Extracts basic information of a given graph representation
  • slgembed SLGEMBED Solves the general graph-based embedding
  • 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 = slgbfe(X, G, Gc, dy, fm, varargin)
0002 %SLGBFE Performs Graph-based Feature Extraction Learning
0003 %
0004 % $ Syntax $
0005 %   - T = slgbfe(X, G, Gc, dy, fm, ...)
0006 %
0007 % $ Arguments $
0008 %   - X:        The sample matrix
0009 %   - G:        The graph to be optimized
0010 %   - Gc:       The constraint graph
0011 %   - dy:       The dimension of feature space
0012 %   - fm:       The formulation type
0013 %   - T:        The learned transform matrix (dx x dy)
0014 %               the transform is done by y = T' * x
0015 %
0016 % $ Description $
0017 %   - T = slgbfe(X, G, Gc, dy, fm, ...) performs graph-based feature
0018 %     extraction learning. It is to solve the following optimization.
0019 %
0020 %       min/max  T'X M(G) X'T,    s.t. T'X M(Gc) X'T = I
0021 %
0022 %     The concrete formulation depends on the formulation type given in
0023 %     fm = {fg, fc}. For fg, it has the following three types:
0024 %       - 'minW':   do minimization with M(G) = W
0025 %       - 'maxW':   do maximization with M(G) = W
0026 %       - 'minL':   do minimization with M(G) = L = D - W
0027 %       - 'maxL':   do maximization with M(G) = L = D - W
0028 %     For fc, it has the following three types:
0029 %       - 'O':      constraint T be orthogonal: T'*T = I (ignore Gc)
0030 %       - 'I':      constraint T'* X * X' * T = I (ignore Gc)
0031 %       - 'WC':     constraint with M(Gc) = W of Gc
0032 %       - 'LC':     constraint with M(Gc) = L of Gc: D - W
0033 %     In the aforementioned formulation, W is the adjacency matrix, while
0034 %     L is the Laplacian matrix. When Gc is ignored (as in 'O' and 'I'),
0035 %     you can just input Gc as [].
0036 %
0037 %     You can further specify the following properties to control the
0038 %     learning process:
0039 %       - 'whparams':  The parameters for doing whitening of M(Gc), please
0040 %                      refer to the function slwhiten_from_cov. The params
0041 %                      are given in a cell array as {method, ...}.
0042 %                      default = {}
0043 %       - 'skip':      The number of components to be skipped. default = 0
0044 %
0045 % $ Remarks $
0046 %   - The implementation is based on slgembed.
0047 %
0048 %   - The function will not centralize the samples, if it is needed please
0049 %     centralize them before invoking.
0050 %
0051 % $ History $
0052 %   - Created by Dahua Lin, on Sep 17, 2006
0053 %
0054 
0055 %% parse and verify input arguments
0056 
0057 if nargin < 5
0058     raise_lackinput('slgbfe', 5);
0059 end
0060 
0061 if ~isnumeric(X) || ndims(X) ~= 2
0062     error('sltoolbox:invalidarg', 'X should be a 2D numeric matrix');
0063 end
0064 n = size(X, 2);
0065 
0066 if ~iscell(fm) || length(fm) ~= 2
0067     error('sltoolbox:invalidarg', 'fm should be a length-2 cell array');
0068 end
0069 fg = fm{1};
0070 fc = fm{2};
0071 
0072 gi = slgraphinfo(G, {[n, n]});
0073 W = sladjmat(G, ...
0074     'valtype', 'numeric', ...
0075     'sparse', strcmp(gi.form, 'adjmat') && issparse(G));
0076 
0077 if strcmp(fc, 'WC') || strcmp(fc, 'LC')
0078     if isempty(Gc)
0079         error('sltoolbox:invalidarg', ...
0080             'When fc is WC or LC, Gc should not be empty');
0081     end
0082     slgraphinfo(Gc, {'adjmat', [n, n]});
0083     if isnumeric(Gc)
0084         Wc = Gc;
0085     else
0086         Wc = double(Gc);
0087     end
0088 else
0089     Wc = [];
0090 end
0091 
0092 
0093 opts.whparams = {};
0094 opts.skip = 0;
0095 opts = slparseprops(opts, varargin{:});
0096 
0097 
0098 %% Construct problem
0099 
0100 % enforce symmetry
0101 W = (W + W') * (1/2);
0102 if ~isempty(Wc)
0103     Wc = (Wc + Wc') * (1/2);
0104 end
0105 
0106 % construct re-formulated G: R
0107 switch fg
0108     case 'maxW'
0109         R = X * W * X';
0110         rfg = 'maxW';
0111     case 'minW'
0112         R = X * W * X';
0113         rfg = 'minW';
0114     case 'maxL'
0115         R = X * make_Lmat(W) * X';
0116         rfg = 'maxW';
0117     case 'minL'
0118         R = X * make_Lmat(W) * X';
0119         rfg = 'minW';
0120     otherwise
0121         error('sltoolbox:invalidarg', 'Invalid fg name: %s', fg);
0122 end    
0123 
0124 % construct re-formulated Gc: Rc
0125 switch fc
0126     case 'O'
0127         Rc = [];
0128         rfc = 'I';
0129     case 'I'
0130         Rc = X * X';
0131         rfc = 'WC';
0132     case 'WC'
0133         Rc = X * Wc * X';
0134         rfc = 'WC';
0135     case 'LC'
0136         Rc = X * make_Lmat(Wc) * X';
0137         rfc = 'WC';
0138     otherwise
0139         error('sltoolbox:invalidarg', 'Invalid fc name: %s', fc);
0140 end
0141 
0142 
0143 %% solve problem
0144 
0145 Y = slgembed(R, Rc, dy, {rfg, rfc}, ...
0146     'inv', opts.whparams, ...
0147     'skip', opts.skip);                 
0148 T = Y';
0149 
0150 
0151 %% Computational routines
0152 
0153 function L = make_Lmat(W)
0154 
0155 vD = sum(W, 1)';
0156 if issparse(vD)
0157     vD = full(vD);
0158 end
0159 
0160 n = size(W, 1);
0161 if issparse(W)
0162     D = sparse((1:n)', (1:n)', vD, n, n, n);
0163     L = D - W;
0164 else
0165     L = -W;
0166     dinds = (1:n)'*(n+1)-n;
0167     L(dinds) = L(dinds) + vD;
0168 end
0169

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

Contact us at files@mathworks.com