about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/netlab3.3/mdndist2.m
diff options
context:
space:
mode:
authorziejd22017-09-28 15:04:40 -0500
committerziejd22017-09-28 15:04:40 -0500
commit8070dc963753142bb86c4ed698d91fd623ed28e7 (patch)
treed0f6dd8fc46a49b819aa55c1a90faa14d8448883 /sourcecodes/bnt-master/netlab3.3/mdndist2.m
parent7cc31810d53176e805532b2789955f4eedbce6bb (diff)
downloadBNW-8070dc963753142bb86c4ed698d91fd623ed28e7.tar.gz
BNW using Octave instead of Matlab.
This version of BNW should perform the same as the original version. The only difference is that it uses Octave instead of Matlab when running BayesNet Toolbox during parameter learning.

I am calling this BNW_1.02. It can be accessed at:
compbio.uthsc.edu/BNW_1.02
Diffstat (limited to 'sourcecodes/bnt-master/netlab3.3/mdndist2.m')
-rw-r--r--sourcecodes/bnt-master/netlab3.3/mdndist2.m51
1 files changed, 51 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/netlab3.3/mdndist2.m b/sourcecodes/bnt-master/netlab3.3/mdndist2.m
new file mode 100644
index 00000000..d7ed93d3
--- /dev/null
+++ b/sourcecodes/bnt-master/netlab3.3/mdndist2.m
@@ -0,0 +1,51 @@
+function n2 = mdndist2(mixparams, t)
+%MDNDIST2 Calculates squared distance between centres of Gaussian kernels and data
+%
+%	Description
+%	N2 = MDNDIST2(MIXPARAMS, T) takes takes the centres of the Gaussian
+%	contained in  MIXPARAMS and the target data matrix, T, and computes
+%	the squared  Euclidean distance between them.  If T has M rows and N
+%	columns, then the CENTRES field in the MIXPARAMS structure should
+%	have M rows and N*MIXPARAMS.NCENTRES columns: the centres in each row
+%	relate to the corresponding row in T. The result has M rows and
+%	MIXPARAMS.NCENTRES columns. The I, Jth entry is the  squared distance
+%	from the Ith row of X to the Jth centre in the Ith row of
+%	MIXPARAMS.CENTRES.
+%
+%	See also
+%	MDNFWD, MDNPROB
+%
+
+%	Copyright (c) Ian T Nabney (1996-2001)
+%	David J Evans (1998)
+
+% Check arguments for consistency
+errstring = consist(mixparams, 'mdnmixes');
+if ~isempty(errstring)
+  error(errstring);
+end
+
+ncentres   = mixparams.ncentres;
+dim_target = mixparams.dim_target;
+ntarget    = size(t, 1);
+if ntarget ~= size(mixparams.centres, 1)
+  error('Number of targets does not match number of mixtures')
+end
+if size(t, 2) ~= mixparams.dim_target
+  error('Target dimension does not match mixture dimension')
+end
+
+% Build t that suits parameters, that is repeat t for each centre
+t = kron(ones(1, ncentres), t);
+
+% Do subtraction and square
+diff2 = (t - mixparams.centres).^2;
+
+% Reshape and sum each component
+diff2 = reshape(diff2', dim_target, (ntarget*ncentres))';
+n2 = sum(diff2, 2);
+
+% Calculate the sum of distance, and reshape
+% so that we have a distance for each centre per target
+n2 = reshape(n2, ncentres, ntarget)';
+