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

sldists2kernels

PURPOSE ^

SLDISTS2KERNELS Computes the inner products from distances

SYNOPSIS ^

function K = sldists2kernels(D, ty)

DESCRIPTION ^

SLDISTS2KERNELS Computes the inner products from distances

 $ Syntax $
   - K = sldists2kernels(D)
   - K = sldists2kernels(D, 'sqr')

 $ Arguments $
   - D:        The pairwise distance matrix
   - K:        The pairwise inner product matrix (kernel matrix)
   
 $ Description $
   - K = sldists2kernels(D) computes the inner products between samples
     pairwisely with the pairwise norms given. Assume that the samples 
     are in an Euclidean linear space, and are centralized.

   - K = sldists2kernels(D, 'sqr') performs the calculation with the 
     input D matrix containing the square distances.

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

CROSS-REFERENCE INFORMATION ^

This function calls:
This function is called by:
  • slcmds SLMDS Performs Classical Multidimensional scaling

SOURCE CODE ^

0001 function K = sldists2kernels(D, ty)
0002 %SLDISTS2KERNELS Computes the inner products from distances
0003 %
0004 % $ Syntax $
0005 %   - K = sldists2kernels(D)
0006 %   - K = sldists2kernels(D, 'sqr')
0007 %
0008 % $ Arguments $
0009 %   - D:        The pairwise distance matrix
0010 %   - K:        The pairwise inner product matrix (kernel matrix)
0011 %
0012 % $ Description $
0013 %   - K = sldists2kernels(D) computes the inner products between samples
0014 %     pairwisely with the pairwise norms given. Assume that the samples
0015 %     are in an Euclidean linear space, and are centralized.
0016 %
0017 %   - K = sldists2kernels(D, 'sqr') performs the calculation with the
0018 %     input D matrix containing the square distances.
0019 %
0020 % $ History $
0021 %   - Created by Dahua Lin, on Sep 8th, 2006
0022 %
0023 
0024 %% parse and verify input
0025 
0026 if isempty(D) 
0027     K = [];
0028     return;
0029 end
0030 
0031 if ~isnumeric(D) || ndims(D) ~= 2 || size(D,1) ~= size(D,2)
0032     error('sltoolbox:invalidarg', ...
0033         'D should be a square matrix');
0034 end
0035 
0036 if nargin >= 2 && strcmpi(ty, 'sqr')
0037     is_sqr = true;
0038 else
0039     is_sqr = false;
0040 end
0041 
0042 %% compute
0043 
0044 % preprocess
0045 
0046 if ~is_sqr
0047     K = D .* D;     % make squares
0048 else
0049     K = D;
0050 end
0051 K = 0.5 * (K + K'); % enforce symmetry
0052 
0053 % compute
0054 n = size(K, 1);
0055 
0056 s = sum(K, 1);
0057 t = sum(s);
0058 
0059 s = s / n;
0060 t = t / (n*n);
0061 
0062 for i = 1 : n
0063     K(i,:) = K(i,:) - s(i);
0064 end
0065 for i = 1 : n
0066     K(:,i) = K(:,i) - s(i);
0067 end
0068 K = K + t;
0069 
0070 K = (-0.5) * K;
0071     
0072 
0073 
0074 
0075     
0076     
0077     
0078     
0079     
0080

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

Contact us at files@mathworks.com