Daniel@0: function [loglik, errors] = mhmm_logprob(data, prior, transmat, mu, Sigma, mixmat) Daniel@0: % LOG_LIK_MHMM Compute the log-likelihood of a dataset using a (mixture of) Gaussians HMM Daniel@0: % [loglik, errors] = log_lik_mhmm(data, prior, transmat, mu, sigma, mixmat) Daniel@0: % Daniel@0: % data{m}(:,t) or data(:,t,m) if all cases have same length Daniel@0: % errors is a list of the cases which received a loglik of -infinity Daniel@0: % Daniel@0: % Set mixmat to ones(Q,1) or omit it if there is only 1 mixture component Daniel@0: Daniel@0: Q = length(prior); Daniel@0: if size(mixmat,1) ~= Q % trap old syntax Daniel@0: error('mixmat should be QxM') Daniel@0: end Daniel@0: if nargin < 6, mixmat = ones(Q,1); end Daniel@0: Daniel@0: if ~iscell(data) Daniel@0: data = num2cell(data, [1 2]); % each elt of the 3rd dim gets its own cell Daniel@0: end Daniel@0: ncases = length(data); Daniel@0: Daniel@0: loglik = 0; Daniel@0: errors = []; Daniel@0: for m=1:ncases Daniel@0: obslik = mixgauss_prob(data{m}, mu, Sigma, mixmat); Daniel@0: [alpha, beta, gamma, ll] = fwdback(prior, transmat, obslik, 'fwd_only', 1); Daniel@0: if ll==-inf Daniel@0: errors = [errors m]; Daniel@0: end Daniel@0: loglik = loglik + ll; Daniel@0: end