annotate toolboxes/FullBNT-1.0.7/netlab3.3/mdnprob.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 [prob,a] = mdnprob(mixparams, t)
wolffd@0 2 %MDNPROB Computes the data probability likelihood for an MDN mixture structure.
wolffd@0 3 %
wolffd@0 4 % Description
wolffd@0 5 % PROB = MDNPROB(MIXPARAMS, T) computes the probability P(T) of each
wolffd@0 6 % data vector in T under the Gaussian mixture model represented by the
wolffd@0 7 % corresponding entries in MIXPARAMS. Each row of T represents a single
wolffd@0 8 % vector.
wolffd@0 9 %
wolffd@0 10 % [PROB, A] = MDNPROB(MIXPARAMS, T) also computes the activations A
wolffd@0 11 % (i.e. the probability P(T|J) of the data conditioned on each
wolffd@0 12 % component density) for a Gaussian mixture model.
wolffd@0 13 %
wolffd@0 14 % See also
wolffd@0 15 % MDNERR, MDNPOST
wolffd@0 16 %
wolffd@0 17
wolffd@0 18 % Copyright (c) Ian T Nabney (1996-2001)
wolffd@0 19 % David J Evans (1998)
wolffd@0 20
wolffd@0 21 % Check arguments for consistency
wolffd@0 22 errstring = consist(mixparams, 'mdnmixes');
wolffd@0 23 if ~isempty(errstring)
wolffd@0 24 error(errstring);
wolffd@0 25 end
wolffd@0 26
wolffd@0 27 ntarget = size(t, 1);
wolffd@0 28 if ntarget ~= size(mixparams.centres, 1)
wolffd@0 29 error('Number of targets does not match number of mixtures')
wolffd@0 30 end
wolffd@0 31 if size(t, 2) ~= mixparams.dim_target
wolffd@0 32 error('Target dimension does not match mixture dimension')
wolffd@0 33 end
wolffd@0 34
wolffd@0 35 dim_target = mixparams.dim_target;
wolffd@0 36 ntarget = size(t, 1);
wolffd@0 37
wolffd@0 38 % Calculate squared norm matrix, of dimension (ndata, ncentres)
wolffd@0 39 % vector (ntarget * ncentres)
wolffd@0 40 dist2 = mdndist2(mixparams, t);
wolffd@0 41
wolffd@0 42 % Calculate variance factors
wolffd@0 43 variance = 2.*mixparams.covars;
wolffd@0 44
wolffd@0 45 % Compute the normalisation term
wolffd@0 46 normal = ((2.*pi).*mixparams.covars).^(dim_target./2);
wolffd@0 47
wolffd@0 48 % Now compute the activations
wolffd@0 49 a = exp(-(dist2./variance))./normal;
wolffd@0 50
wolffd@0 51 % Accumulate negative log likelihood of targets
wolffd@0 52 prob = mixparams.mixcoeffs.*a;