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