Mercurial > hg > camir-aes2014
annotate toolboxes/FullBNT-1.0.7/netlab3.3/gmmpost.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 [post, a] = gmmpost(mix, x) |
wolffd@0 | 2 %GMMPOST Computes the class posterior probabilities of a Gaussian mixture model. |
wolffd@0 | 3 % |
wolffd@0 | 4 % Description |
wolffd@0 | 5 % This function computes the posteriors POST (i.e. the probability of |
wolffd@0 | 6 % each component conditioned on the data P(J|X)) for a Gaussian mixture |
wolffd@0 | 7 % model. The data structure MIX defines the mixture model, while the |
wolffd@0 | 8 % matrix X contains the data vectors. Each row of X represents a |
wolffd@0 | 9 % single vector. |
wolffd@0 | 10 % |
wolffd@0 | 11 % See also |
wolffd@0 | 12 % GMM, GMMACTIV, GMMPROB |
wolffd@0 | 13 % |
wolffd@0 | 14 |
wolffd@0 | 15 % Copyright (c) Ian T Nabney (1996-2001) |
wolffd@0 | 16 |
wolffd@0 | 17 % Check that inputs are consistent |
wolffd@0 | 18 errstring = consist(mix, 'gmm', x); |
wolffd@0 | 19 if ~isempty(errstring) |
wolffd@0 | 20 error(errstring); |
wolffd@0 | 21 end |
wolffd@0 | 22 |
wolffd@0 | 23 ndata = size(x, 1); |
wolffd@0 | 24 |
wolffd@0 | 25 a = gmmactiv(mix, x); |
wolffd@0 | 26 |
wolffd@0 | 27 post = (ones(ndata, 1)*mix.priors).*a; |
wolffd@0 | 28 s = sum(post, 2); |
wolffd@0 | 29 if any(s==0) |
wolffd@0 | 30 warning('Some zero posterior probabilities') |
wolffd@0 | 31 % Set any zeros to one before dividing |
wolffd@0 | 32 zero_rows = find(s==0); |
wolffd@0 | 33 s = s + (s==0); |
wolffd@0 | 34 post(zero_rows, :) = 1/mix.ncentres; |
wolffd@0 | 35 end |
wolffd@0 | 36 post = post./(s*ones(1, mix.ncentres)); |