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