about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/netlab3.3/dist2.m
diff options
context:
space:
mode:
Diffstat (limited to 'sourcecodes/bnt-master/netlab3.3/dist2.m')
-rw-r--r--sourcecodes/bnt-master/netlab3.3/dist2.m31
1 files changed, 31 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/netlab3.3/dist2.m b/sourcecodes/bnt-master/netlab3.3/dist2.m
new file mode 100644
index 00000000..b5f1c646
--- /dev/null
+++ b/sourcecodes/bnt-master/netlab3.3/dist2.m
@@ -0,0 +1,31 @@
+function n2 = dist2(x, c)
+%DIST2	Calculates squared distance between two sets of points.
+%
+%	Description
+%	D = DIST2(X, C) takes two matrices of vectors and calculates the
+%	squared Euclidean distance between them.  Both matrices must be of
+%	the same column dimension.  If X has M rows and N columns, and C has
+%	L rows and N columns, then the result has M rows and L columns.  The
+%	I, Jth entry is the  squared distance from the Ith row of X to the
+%	Jth row of C.
+%
+%	See also
+%	GMMACTIV, KMEANS, RBFFWD
+%
+
+%	Copyright (c) Ian T Nabney (1996-2001)
+
+[ndata, dimx] = size(x);
+[ncentres, dimc] = size(c);
+if dimx ~= dimc
+	error('Data dimension does not match dimension of centres')
+end
+
+n2 = (ones(ncentres, 1) * sum((x.^2)', 1))' + ...
+  ones(ndata, 1) * sum((c.^2)',1) - ...
+  2.*(x*(c'));
+
+% Rounding errors occasionally cause negative entries in n2
+if any(any(n2<0))
+  n2(n2<0) = 0;
+end
\ No newline at end of file