annotate toolboxes/FullBNT-1.0.7/netlab3.3/mdndist2.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 = mdndist2(mixparams, t)
wolffd@0 2 %MDNDIST2 Calculates squared distance between centres of Gaussian kernels and data
wolffd@0 3 %
wolffd@0 4 % Description
wolffd@0 5 % N2 = MDNDIST2(MIXPARAMS, T) takes takes the centres of the Gaussian
wolffd@0 6 % contained in MIXPARAMS and the target data matrix, T, and computes
wolffd@0 7 % the squared Euclidean distance between them. If T has M rows and N
wolffd@0 8 % columns, then the CENTRES field in the MIXPARAMS structure should
wolffd@0 9 % have M rows and N*MIXPARAMS.NCENTRES columns: the centres in each row
wolffd@0 10 % relate to the corresponding row in T. The result has M rows and
wolffd@0 11 % MIXPARAMS.NCENTRES columns. The I, Jth entry is the squared distance
wolffd@0 12 % from the Ith row of X to the Jth centre in the Ith row of
wolffd@0 13 % MIXPARAMS.CENTRES.
wolffd@0 14 %
wolffd@0 15 % See also
wolffd@0 16 % MDNFWD, MDNPROB
wolffd@0 17 %
wolffd@0 18
wolffd@0 19 % Copyright (c) Ian T Nabney (1996-2001)
wolffd@0 20 % David J Evans (1998)
wolffd@0 21
wolffd@0 22 % Check arguments for consistency
wolffd@0 23 errstring = consist(mixparams, 'mdnmixes');
wolffd@0 24 if ~isempty(errstring)
wolffd@0 25 error(errstring);
wolffd@0 26 end
wolffd@0 27
wolffd@0 28 ncentres = mixparams.ncentres;
wolffd@0 29 dim_target = mixparams.dim_target;
wolffd@0 30 ntarget = size(t, 1);
wolffd@0 31 if ntarget ~= size(mixparams.centres, 1)
wolffd@0 32 error('Number of targets does not match number of mixtures')
wolffd@0 33 end
wolffd@0 34 if size(t, 2) ~= mixparams.dim_target
wolffd@0 35 error('Target dimension does not match mixture dimension')
wolffd@0 36 end
wolffd@0 37
wolffd@0 38 % Build t that suits parameters, that is repeat t for each centre
wolffd@0 39 t = kron(ones(1, ncentres), t);
wolffd@0 40
wolffd@0 41 % Do subtraction and square
wolffd@0 42 diff2 = (t - mixparams.centres).^2;
wolffd@0 43
wolffd@0 44 % Reshape and sum each component
wolffd@0 45 diff2 = reshape(diff2', dim_target, (ntarget*ncentres))';
wolffd@0 46 n2 = sum(diff2, 2);
wolffd@0 47
wolffd@0 48 % Calculate the sum of distance, and reshape
wolffd@0 49 % so that we have a distance for each centre per target
wolffd@0 50 n2 = reshape(n2, ncentres, ntarget)';
wolffd@0 51