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