annotate toolboxes/FullBNT-1.0.7/HMM/mhmm_logprob.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 [loglik, errors] = mhmm_logprob(data, prior, transmat, mu, Sigma, mixmat)
wolffd@0 2 % LOG_LIK_MHMM Compute the log-likelihood of a dataset using a (mixture of) Gaussians HMM
wolffd@0 3 % [loglik, errors] = log_lik_mhmm(data, prior, transmat, mu, sigma, mixmat)
wolffd@0 4 %
wolffd@0 5 % data{m}(:,t) or data(:,t,m) if all cases have same length
wolffd@0 6 % errors is a list of the cases which received a loglik of -infinity
wolffd@0 7 %
wolffd@0 8 % Set mixmat to ones(Q,1) or omit it if there is only 1 mixture component
wolffd@0 9
wolffd@0 10 Q = length(prior);
wolffd@0 11 if size(mixmat,1) ~= Q % trap old syntax
wolffd@0 12 error('mixmat should be QxM')
wolffd@0 13 end
wolffd@0 14 if nargin < 6, mixmat = ones(Q,1); end
wolffd@0 15
wolffd@0 16 if ~iscell(data)
wolffd@0 17 data = num2cell(data, [1 2]); % each elt of the 3rd dim gets its own cell
wolffd@0 18 end
wolffd@0 19 ncases = length(data);
wolffd@0 20
wolffd@0 21 loglik = 0;
wolffd@0 22 errors = [];
wolffd@0 23 for m=1:ncases
wolffd@0 24 obslik = mixgauss_prob(data{m}, mu, Sigma, mixmat);
wolffd@0 25 [alpha, beta, gamma, ll] = fwdback(prior, transmat, obslik, 'fwd_only', 1);
wolffd@0 26 if ll==-inf
wolffd@0 27 errors = [errors m];
wolffd@0 28 end
wolffd@0 29 loglik = loglik + ll;
wolffd@0 30 end