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

slkernelembed

PURPOSE ^

SLKERNELEMBED Finds an embedding space to preserve inner products

SYNOPSIS ^

function [X, spectrum] = slkernelembed(K, d, w)

DESCRIPTION ^

SLKERNELEMBED Finds an embedding space to preserve inner products

 $ Syntax $
   - X = slkernelembed(K, d)
   - X = slkernelembed(K, d, w)
   - [X, info] = slkernelembed(...)

 $ Arguments $
   - K:        The pairwise inner product matrix (kernel matrix): n x n
   - d:        The dimension of the embedded space 
   - w:        The weights of the samples: 1 x n
   - X:        The embeded sample coordinates: d x n
   - spectrum: The eigenvalues of the embeded space (dx1)

 $ Description $
   - X = slkernelembed(K, d, w) finds an embedding space in which the
     the inner product structure of the original sample set is best
     preserved in terms of square error of reconstructed kernel matrix.

   - X = slkernelembed(K, d, w) runs the algorithm on weighted samples.

   - [X, spectrum] = slkernelembed(...) additionally outputs the
     eigen-spectrum of the embedding space, which is a column vector
     of eigenvalues associated with all dimensions.

 $ Remarks $
   - The embeded dimension d should be less than the number of samples n.

   - The implementation is based on EVD decomposition.

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

CROSS-REFERENCE INFORMATION ^

This function calls:
  • slsymeig SLSYMEIG Compute the eigenvalues and eigenvectors for symmetric matrix
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
This function is called by:
  • slcmds SLMDS Performs Classical Multidimensional scaling

SOURCE CODE ^

0001 function [X, spectrum] = slkernelembed(K, d, w)
0002 %SLKERNELEMBED Finds an embedding space to preserve inner products
0003 %
0004 % $ Syntax $
0005 %   - X = slkernelembed(K, d)
0006 %   - X = slkernelembed(K, d, w)
0007 %   - [X, info] = slkernelembed(...)
0008 %
0009 % $ Arguments $
0010 %   - K:        The pairwise inner product matrix (kernel matrix): n x n
0011 %   - d:        The dimension of the embedded space
0012 %   - w:        The weights of the samples: 1 x n
0013 %   - X:        The embeded sample coordinates: d x n
0014 %   - spectrum: The eigenvalues of the embeded space (dx1)
0015 %
0016 % $ Description $
0017 %   - X = slkernelembed(K, d, w) finds an embedding space in which the
0018 %     the inner product structure of the original sample set is best
0019 %     preserved in terms of square error of reconstructed kernel matrix.
0020 %
0021 %   - X = slkernelembed(K, d, w) runs the algorithm on weighted samples.
0022 %
0023 %   - [X, spectrum] = slkernelembed(...) additionally outputs the
0024 %     eigen-spectrum of the embedding space, which is a column vector
0025 %     of eigenvalues associated with all dimensions.
0026 %
0027 % $ Remarks $
0028 %   - The embeded dimension d should be less than the number of samples n.
0029 %
0030 %   - The implementation is based on EVD decomposition.
0031 %
0032 % $ History $
0033 %   - Created by Dahua Lin, on Sep 8, 2006
0034 %
0035 
0036 %% parse and verify input arguments
0037 
0038 if nargin < 2
0039     raise_lackinput('slkernelembed', 2);
0040 end
0041 
0042 if ndims(K) ~= 2 || size(K, 1) ~= size(K, 2)
0043     error('sltoolbox:invalidarg', ...
0044         'The K should be a square matrix');
0045 end
0046 n = size(K, 1);
0047 
0048 if d >= n
0049     error('sltoolbox:exceedbound', ...
0050         'The dimension d should be less than the number of samples n');
0051 end
0052 
0053 if nargin < 3
0054     w = [];
0055 else
0056     if ~isempty(w)
0057         if ~isequal(size(w), [1, n])
0058             error('sltoolbox:sizmismatch', ...
0059                 'If w is specified, it should be an 1 x n row vector');
0060         end
0061     end
0062 end
0063 
0064 
0065 %% compute
0066 
0067 % enforce symmetry
0068 K = 0.5 * (K + K');
0069 
0070 % assign weights
0071 if ~isempty(w)
0072     for i = 1 : n
0073         K(i,:) = K(i,:) * w(i);
0074     end
0075     for i = 1 : n
0076         K(:,i) = K(:,i) * w(i);
0077     end
0078 end
0079 
0080 % decompose
0081 [spectrum, X] = slsymeig(K, d);
0082 
0083 spectrum = max(spectrum, 0);
0084 s = sqrt(spectrum);
0085 for i = 1 : d
0086     X(:,i) = X(:,i) * s(i);
0087 end
0088 X = X';
0089 
0090 % de-weights
0091 if ~isempty(w)
0092     for i = 1 : n
0093         X(:,i) = X(:,i) / w(i);
0094     end
0095 end
0096     
0097 
0098 
0099 
0100 
0101 
0102 
0103 
0104 
0105 
0106    
0107 
0108 
0109 
0110 
0111 
0112 
0113 
0114

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

Contact us at files@mathworks.com