Mercurial > hg > camir-aes2014
annotate 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 | 
| rev | line source | 
|---|---|
| wolffd@0 | 1 function n2 = dist2(x, c) | 
| wolffd@0 | 2 %DIST2 Calculates squared distance between two sets of points. | 
| wolffd@0 | 3 % | 
| wolffd@0 | 4 % Description | 
| wolffd@0 | 5 % D = DIST2(X, C) takes two matrices of vectors and calculates the | 
| wolffd@0 | 6 % squared Euclidean distance between them. Both matrices must be of | 
| wolffd@0 | 7 % the same column dimension. If X has M rows and N columns, and C has | 
| wolffd@0 | 8 % L rows and N columns, then the result has M rows and L columns. The | 
| wolffd@0 | 9 % I, Jth entry is the squared distance from the Ith row of X to the | 
| wolffd@0 | 10 % Jth row of C. | 
| wolffd@0 | 11 % | 
| wolffd@0 | 12 % See also | 
| wolffd@0 | 13 % GMMACTIV, KMEANS, RBFFWD | 
| wolffd@0 | 14 % | 
| wolffd@0 | 15 | 
| wolffd@0 | 16 % Copyright (c) Ian T Nabney (1996-2001) | 
| wolffd@0 | 17 | 
| wolffd@0 | 18 [ndata, dimx] = size(x); | 
| wolffd@0 | 19 [ncentres, dimc] = size(c); | 
| wolffd@0 | 20 if dimx ~= dimc | 
| wolffd@0 | 21 error('Data dimension does not match dimension of centres') | 
| wolffd@0 | 22 end | 
| wolffd@0 | 23 | 
| wolffd@0 | 24 n2 = (ones(ncentres, 1) * sum((x.^2)', 1))' + ... | 
| wolffd@0 | 25 ones(ndata, 1) * sum((c.^2)',1) - ... | 
| wolffd@0 | 26 2.*(x*(c')); | 
| wolffd@0 | 27 | 
| wolffd@0 | 28 % Rounding errors occasionally cause negative entries in n2 | 
| wolffd@0 | 29 if any(any(n2<0)) | 
| wolffd@0 | 30 n2(n2<0) = 0; | 
| wolffd@0 | 31 end | 
