comparison toolboxes/FullBNT-1.0.7/netlab3.3/dist2.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function n2 = dist2(x, c)
2 %DIST2 Calculates squared distance between two sets of points.
3 %
4 % Description
5 % D = DIST2(X, C) takes two matrices of vectors and calculates the
6 % squared Euclidean distance between them. Both matrices must be of
7 % the same column dimension. If X has M rows and N columns, and C has
8 % L rows and N columns, then the result has M rows and L columns. The
9 % I, Jth entry is the squared distance from the Ith row of X to the
10 % Jth row of C.
11 %
12 % See also
13 % GMMACTIV, KMEANS, RBFFWD
14 %
15
16 % Copyright (c) Ian T Nabney (1996-2001)
17
18 [ndata, dimx] = size(x);
19 [ncentres, dimc] = size(c);
20 if dimx ~= dimc
21 error('Data dimension does not match dimension of centres')
22 end
23
24 n2 = (ones(ncentres, 1) * sum((x.^2)', 1))' + ...
25 ones(ndata, 1) * sum((c.^2)',1) - ...
26 2.*(x*(c'));
27
28 % Rounding errors occasionally cause negative entries in n2
29 if any(any(n2<0))
30 n2(n2<0) = 0;
31 end