Home > src > calcPairwiseDistances.m

calcPairwiseDistances

PURPOSE ^

calculate the pairwise squared distance matrix (2-norm distance)

SYNOPSIS ^

function [ aveDist allDist ] = calcPairwiseDistances( X )

DESCRIPTION ^

 calculate the pairwise squared distance matrix (2-norm distance)
 Samuel Rivera
 Oct 29, 2010
 X in pxN, N samples
 calculate the pairwise squared distance matrix (2-norm distance)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % calculate the pairwise squared distance matrix (2-norm distance)
0002 % Samuel Rivera
0003 % Oct 29, 2010
0004 % X in pxN, N samples
0005 % calculate the pairwise squared distance matrix (2-norm distance)
0006 
0007 function [ aveDist allDist ] = calcPairwiseDistances( X )
0008 
0009 nAll = size(X,2);
0010 
0011 A = X'*X;
0012 dA = diag(A);
0013 DD = repmat(dA,1,nAll) + repmat(dA',nAll,1) - 2*A;
0014 
0015 %get all entries in upper diagonal, eliminating the diagonal entries
0016 allDist = [];
0017 for i1 = 1:nAll-1
0018     dtemp = DD(i1, i1+1:end);
0019     allDist = [ allDist; dtemp(:)];
0020     
0021 end
0022 
0023 aveDist = mean(allDist);
0024

Generated on Wed 20-Jan-2016 11:50:43 by m2html © 2005