Daniel@0: function [post, a] = gmmpost(mix, x) Daniel@0: %GMMPOST Computes the class posterior probabilities of a Gaussian mixture model. Daniel@0: % Daniel@0: % Description Daniel@0: % This function computes the posteriors POST (i.e. the probability of Daniel@0: % each component conditioned on the data P(J|X)) for a Gaussian mixture Daniel@0: % model. The data structure MIX defines the mixture model, while the Daniel@0: % matrix X contains the data vectors. Each row of X represents a Daniel@0: % single vector. Daniel@0: % Daniel@0: % See also Daniel@0: % GMM, GMMACTIV, GMMPROB Daniel@0: % Daniel@0: Daniel@0: % Copyright (c) Ian T Nabney (1996-2001) Daniel@0: Daniel@0: % Check that inputs are consistent Daniel@0: errstring = consist(mix, 'gmm', x); Daniel@0: if ~isempty(errstring) Daniel@0: error(errstring); Daniel@0: end Daniel@0: Daniel@0: ndata = size(x, 1); Daniel@0: Daniel@0: a = gmmactiv(mix, x); Daniel@0: Daniel@0: post = (ones(ndata, 1)*mix.priors).*a; Daniel@0: s = sum(post, 2); Daniel@0: if any(s==0) Daniel@0: warning('Some zero posterior probabilities') Daniel@0: % Set any zeros to one before dividing Daniel@0: zero_rows = find(s==0); Daniel@0: s = s + (s==0); Daniel@0: post(zero_rows, :) = 1/mix.ncentres; Daniel@0: end Daniel@0: post = post./(s*ones(1, mix.ncentres));