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 sllocaltanspace
Home > sltoolbox > manifold > sllocaltanspace.m

sllocaltanspace

PURPOSE ^

SLLOCALTANSPACE Solves the local tangent spaces

SYNOPSIS ^

function [LM, LP, LS] = sllocaltanspace(X0, G, dl)

DESCRIPTION ^

SLLOCALTANSPACE Solves the local tangent spaces

 $ Syntax $
   - [LM, LP] = sllocaltanspace(X0, G, dl)
   - [LM, LP, LS] = sllocaltanspace(...)

 $ Arguments $
   - X0:       The referenced sample matrix (d0 x n0)
   - G:        The neighborhood graph (n0 x n)
   - dl:       The dimension of local tangent spaces
               (should be strictly less than d0 and n0)
   - LM:       The local means (d0 x n)
   - LP:       The local tangent space basis (d0 x dl x n)
   - LS:       The local spectrum (dl x n)

 $ Description $
   - [LM, LP] = sllocaltanspace(X0, G, dl) solves the local tangent
     spaces based on the neighborhood graph G. Suppose G is n0 x n,
     (n0 source points and n target points), then it solves the local
     tangent spaces at n target points with the space constructed with
     their neighbors in X0. If G is valued, the values in G are the 
     weights of the samples in constructing local tangent space.

   - [LM, LP, LS] = sllocaltanspace(...) additionally outputs the
     eigen-spectrum of the local spaces. 

 $ Remarks $
   - The local dimensions are sorted in descending order of the 
     corresponding eigenvalues. In the case of local rank < dl,
     for the last dl - rank dimensions, the eigenvalues are set to
     zeros, and the eigenvectors are set to zero vectors.

 $ History $
   - Created by Dahua Lin, on Sep 13rd, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
  • sladdvec SLADDVEC adds a vector to columns or rows of a matrix
  • slmulvec SLMULVEC multiplies a vector to columns or rows of a matrix
  • slnormalize SLNORMALIZE Normalize the sub-arrays
  • slsymeig SLSYMEIG Compute the eigenvalues and eigenvectors for symmetric matrix
  • sladjmat SLADJMAT Constructs the adjacency matrix representation of a graph
  • slgraphinfo SLGRAPHINFO Extracts basic information of a given graph representation
  • slmean SLMEAN Compute the mean vector of samples
This function is called by:
  • slltsa SLLTSA Performs Local Tangent Space Alignment Learning

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [LM, LP, LS] = sllocaltanspace(X0, G, dl) 
0002 %SLLOCALTANSPACE Solves the local tangent spaces
0003 %
0004 % $ Syntax $
0005 %   - [LM, LP] = sllocaltanspace(X0, G, dl)
0006 %   - [LM, LP, LS] = sllocaltanspace(...)
0007 %
0008 % $ Arguments $
0009 %   - X0:       The referenced sample matrix (d0 x n0)
0010 %   - G:        The neighborhood graph (n0 x n)
0011 %   - dl:       The dimension of local tangent spaces
0012 %               (should be strictly less than d0 and n0)
0013 %   - LM:       The local means (d0 x n)
0014 %   - LP:       The local tangent space basis (d0 x dl x n)
0015 %   - LS:       The local spectrum (dl x n)
0016 %
0017 % $ Description $
0018 %   - [LM, LP] = sllocaltanspace(X0, G, dl) solves the local tangent
0019 %     spaces based on the neighborhood graph G. Suppose G is n0 x n,
0020 %     (n0 source points and n target points), then it solves the local
0021 %     tangent spaces at n target points with the space constructed with
0022 %     their neighbors in X0. If G is valued, the values in G are the
0023 %     weights of the samples in constructing local tangent space.
0024 %
0025 %   - [LM, LP, LS] = sllocaltanspace(...) additionally outputs the
0026 %     eigen-spectrum of the local spaces.
0027 %
0028 % $ Remarks $
0029 %   - The local dimensions are sorted in descending order of the
0030 %     corresponding eigenvalues. In the case of local rank < dl,
0031 %     for the last dl - rank dimensions, the eigenvalues are set to
0032 %     zeros, and the eigenvectors are set to zero vectors.
0033 %
0034 % $ History $
0035 %   - Created by Dahua Lin, on Sep 13rd, 2006
0036 %
0037 
0038 %% parse and verify input arguments
0039 
0040 if ~isnumeric(X0) || ndims(X0) ~= 2
0041     error('sltoolbox:invalidarg', ...
0042         'The sample matrix X0 should be a 2D numeric matrix');
0043 end
0044 [d0, n0] = size(X0);
0045 
0046 gi = slgraphinfo(G);
0047 if gi.n ~= n0
0048     error('sltoolbox:invalidarg', ...
0049         'The graph is not consistent with the sample number');
0050 end
0051 if ~strcmp(gi.form, 'adjmat')
0052     G = sladjmat(G, 'sparse', true);
0053 end
0054 n = gi.nt;
0055 
0056 if dl >= d0 || dl >= n0
0057     error('sltoolbox:invalidarg', ...
0058         'The local dimension dl should be strictly less than d0 and n0');
0059 end
0060 
0061 if nargout >= 3
0062     want_sp = true;
0063 else
0064     want_sp = false;
0065 end
0066 
0067 if isnumeric(G)
0068     use_weights = true;
0069 else
0070     use_weights = false;
0071 end
0072 
0073 %% main skeleton
0074 
0075 % prepare storage
0076 LM = zeros(d0, n);
0077 LP = zeros(d0, dl, n);
0078 if want_sp
0079     LS = zeros(dl, n);
0080 end
0081 
0082 % do computation
0083 for i = 1 : n    
0084     localinds = find(G(:,i));
0085     if use_weights
0086         localw = G(localinds, i)';
0087     else
0088         localw = [];
0089     end
0090     localX = X0(:, localinds);
0091     
0092     [cm, cp, csp] = solvelocalspace(localX, localw, d0, dl);
0093     
0094     LM(:,i) = cm;
0095     LP(:,:,i) = cp;
0096     if want_sp
0097         LS(:,i) = csp;
0098     end
0099 end
0100 
0101 
0102 %% core routine to compute local tangent spaces
0103 
0104 function [vmean, P, spectrum] = solvelocalspace(X, w, d0, dl)
0105 
0106 n = size(X, 2);
0107 dm = min([dl, d0, n]);
0108 
0109 % preprocess samples: centralize and weight
0110 vmean = slmean(X, w, true);
0111 X = sladdvec(X, -vmean, 1);
0112 if ~isempty(w)
0113     X = slmulvec(X, w, 2);
0114 end
0115 
0116 % solve eigen-problem
0117 if d0 <= n / 2
0118     C = X * X';
0119     [spectrum, P] = slsymeig(C, dm); 
0120 else
0121     C = X' * X;
0122     [spectrum, P] = slsymeig(C, dm);
0123     P = slnormalize(X * P);
0124 end
0125 
0126 % truncate to rank
0127 rk = sum(spectrum > n * eps(spectrum(1)));
0128 if rk < dm
0129     spectrum = spectrum(1:rk);
0130     P = P(:, 1:rk);    
0131 end
0132 spectrum = spectrum / n;
0133 
0134 % complement to dl
0135 if rk < dl
0136     spectrum = [spectrum; zeros(dl-rk, 1)];
0137     P = [P, zeros(d0, dl-rk)];
0138 end
0139

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

Contact us at files@mathworks.com