Home > subfunctions > ccl_math_distances.m

ccl_math_distances

PURPOSE ^

D = ccl_math_distances (A,B)

SYNOPSIS ^

function D = ccl_math_distances (A, B)

DESCRIPTION ^

 D = ccl_math_distances (A,B)

 calculate the euclidean distance between two datasets A and B

 input:

    A: a dataset with N data points
    B: a dataset with M data points

 output:

    D: euclidean distance between A and B. D is a MxN matrix

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function D = ccl_math_distances (A, B)
0002 % D = ccl_math_distances (A,B)
0003 %
0004 % calculate the euclidean distance between two datasets A and B
0005 %
0006 % input:
0007 %
0008 %    A: a dataset with N data points
0009 %    B: a dataset with M data points
0010 %
0011 % output:
0012 %
0013 %    D: euclidean distance between A and B. D is a MxN matrix
0014 
0015 
0016 
0017 
0018 
0019 % CCL: A MATLAB library for Constraint Consistent Learning
0020 % Copyright (C) 2007  Matthew Howard
0021 % Contact: matthew.j.howard@kcl.ac.uk
0022 %
0023 % This library is free software; you can redistribute it and/or
0024 % modify it under the terms of the GNU Lesser General Public
0025 % License as published by the Free Software Foundation; either
0026 % version 2.1 of the License, or (at your option) any later version.
0027 %
0028 % This library is distributed in the hope that it will be useful,
0029 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0030 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0031 % Lesser General Public License for more details.
0032 %
0033 % You should have received a copy of the GNU Library General Public
0034 % License along with this library; if not, write to the Free
0035 % Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
0036 
0037     numA= size(A,2) ;
0038     numB= size(B,2) ;
0039     A2  = sum(A.^2) ;
0040     B2  = sum(B.^2) ;    
0041     D   = repmat( A2',1, numB ) + repmat( B2, numA, 1) - 2*A'*B ;   
0042 end

Generated on Mon 01-Jan-2018 15:49:39 by m2html © 2005