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

sllocaltancoords

PURPOSE ^

SLLOCALTANCOORDS Computes the local tangent coordinates

SYNOPSIS ^

function [Y, GM] = sllocaltancoords(LM, LP, X, G, ga)

DESCRIPTION ^

SLLOCALTANCOORDS Computes the local tangent coordinates

 $ Syntax $
   - [Y, GM] = sllocaltancoords(LM, LP, X, G)
   - [Y, GM] = sllocaltancoords(LM, LP, X, G, ga);

 $ Arguments $
   - LM:       The local means (d0 x m)
   - LP:       The local space basis (d0 x dl x m)
   - X:        The input samples (d0 x n)
   - G:        The graph indicating which sample is managed by which model
               (1 x n)
   - ga:       The graph arrangement (default = 'N')
                   - 'N': m x n, models as sources, samples as targets
                   - 'T': n x m, samples as sources, models as targets
   - Y:        The computed local coordinates (dl x nnz)

 $ Description $
   - [Y, GM] = sllocaltancoords(LM, LP, X, G) computes the local tangent
     coordinates using the default graph arrangement. For each non-zero
     entry in G, there is a pairs of a space model characterized by 
     a mean vector vm and space basis P and a sample x. Then the local
     tangent coordinates are computed by
           y = P^T * (x - vm)
     If there are nnz non-zero entries in G, then Y has nnz columns. The 
     output graph GM is a sparse matrix, with the values in GM telling 
     the index of the corresponding column in Y.

   - [Y, GM] = sllocaltancoords(LM, LP, X, G, ga) computes the local tangent
     coordinates using the specified graph arrangement. There are two
     arrangements to choose:
       - 'N': G is m x n, models as sources, samples as targets
              the edge connecting the i-th source and the j-th target
              refers to the pair of the i-th model and the j-th sample
       - 'T': G is n x m, samples as sources, models as targets
              the edge connecting the i-th source and the j-th target
              refers to the pair of the i-th sample and the j-th model

 $ Remarks $
   - When map is not specified, the number of models should be equal to
     the number of samples. (m = n)

 $ 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
  • sladjmat SLADJMAT Constructs the adjacency matrix representation of a graph
  • slgraphinfo SLGRAPHINFO Extracts basic information of a given graph representation
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
This function is called by:
  • slltsa SLLTSA Performs Local Tangent Space Alignment Learning

SOURCE CODE ^

0001 function [Y, GM] = sllocaltancoords(LM, LP, X, G, ga)
0002 %SLLOCALTANCOORDS Computes the local tangent coordinates
0003 %
0004 % $ Syntax $
0005 %   - [Y, GM] = sllocaltancoords(LM, LP, X, G)
0006 %   - [Y, GM] = sllocaltancoords(LM, LP, X, G, ga);
0007 %
0008 % $ Arguments $
0009 %   - LM:       The local means (d0 x m)
0010 %   - LP:       The local space basis (d0 x dl x m)
0011 %   - X:        The input samples (d0 x n)
0012 %   - G:        The graph indicating which sample is managed by which model
0013 %               (1 x n)
0014 %   - ga:       The graph arrangement (default = 'N')
0015 %                   - 'N': m x n, models as sources, samples as targets
0016 %                   - 'T': n x m, samples as sources, models as targets
0017 %   - Y:        The computed local coordinates (dl x nnz)
0018 %
0019 % $ Description $
0020 %   - [Y, GM] = sllocaltancoords(LM, LP, X, G) computes the local tangent
0021 %     coordinates using the default graph arrangement. For each non-zero
0022 %     entry in G, there is a pairs of a space model characterized by
0023 %     a mean vector vm and space basis P and a sample x. Then the local
0024 %     tangent coordinates are computed by
0025 %           y = P^T * (x - vm)
0026 %     If there are nnz non-zero entries in G, then Y has nnz columns. The
0027 %     output graph GM is a sparse matrix, with the values in GM telling
0028 %     the index of the corresponding column in Y.
0029 %
0030 %   - [Y, GM] = sllocaltancoords(LM, LP, X, G, ga) computes the local tangent
0031 %     coordinates using the specified graph arrangement. There are two
0032 %     arrangements to choose:
0033 %       - 'N': G is m x n, models as sources, samples as targets
0034 %              the edge connecting the i-th source and the j-th target
0035 %              refers to the pair of the i-th model and the j-th sample
0036 %       - 'T': G is n x m, samples as sources, models as targets
0037 %              the edge connecting the i-th source and the j-th target
0038 %              refers to the pair of the i-th sample and the j-th model
0039 %
0040 % $ Remarks $
0041 %   - When map is not specified, the number of models should be equal to
0042 %     the number of samples. (m = n)
0043 %
0044 % $ History $
0045 %   - Created by Dahua Lin, on Sep 13rd, 2006
0046 %
0047 
0048 %% parse and verify input arguments
0049 
0050 if nargin < 4
0051     raise_lackinput('sllocaltancoords', 4);
0052 end
0053 
0054 [d, m] = size(LM);
0055 [dP, dl, m2] = size(LP);
0056 [dX, n] = size(X);
0057 
0058 if d ~= dP || d ~= dX
0059     error('sltoolbox:sizmismatch', ...
0060         'The sample dimensions are inconsistent among LM, LP and X');
0061 end
0062 if m~= m2
0063     error('sltoolbox:sizmismatch', ...
0064         'The space numbers in LM and LP are inconsistent');
0065 end
0066 
0067 gi = slgraphinfo(G);
0068 
0069 if nargin < 5
0070     ga = 'N';
0071 end
0072 switch ga
0073     case 'N'
0074         if ~isequal([gi.n, gi.nt], [m, n])
0075             error('sltoolbox:sizmismatch', ...
0076                 'The size of the graph does not match the samples and models');
0077         end
0078     case 'T'
0079         if ~isequal([gi.n, gi.nt], [n, m])
0080             error('sltoolbox:sizmismatch', ...
0081                 'The size of the graph does not match the samples and models');
0082         end
0083     otherwise
0084         error('sltoolbox:invalidarg', ...
0085             'Invalid graph arrangement: %s', ga);
0086 end
0087 
0088 
0089 %% main
0090 
0091 % prepare indices
0092 if ~strcmp(gi.form, 'adjmat')
0093     G = sladjmat(G, 'valtype', 'logical', 'sparse', true);
0094 end
0095         
0096 % prepare storage
0097 ny = nnz(G);
0098 Y = zeros(dl, ny);
0099 GM = spalloc(gi.n, gi.nt, ny);
0100 
0101 % main loop
0102 cp = 0;
0103 switch ga
0104     case 'N'
0105         for k = 1 : m
0106             vm = LM(:,k);
0107             P = LP(:,:,k);
0108             ci = find(G(k,:));
0109             curX = X(:, ci);
0110             cn = length(ci);
0111             curY = P' * sladdvec(curX, -vm, 1);
0112             Y(:, cp+1:cp+cn) = curY;
0113             GM(k, ci) = cp+1:cp+cn;
0114             cp = cp + cn;
0115         end
0116     case 'T'
0117         for k = 1 : m
0118             vm = LM(:,k);
0119             P = LP(:,:,k);
0120             ci = find(G(:,k));
0121             curX = X(:, ci);
0122             cn = length(ci);
0123             curY = P' * sladdvec(curX, -vm, 1);
0124             Y(:, cp+1:cp+cn) = curY;
0125             GM(ci, k) = (cp+1:cp+cn)';
0126             cp = cp + cn;
0127         end                        
0128 end
0129 
0130 
0131

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

Contact us at files@mathworks.com