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