annotate toolboxes/FullBNT-1.0.7/netlab3.3/mdndist2.m @ 0:cc4b1211e677 tip

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