annotate toolboxes/FullBNT-1.0.7/HMM/mhmm_logprob.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function [loglik, errors] = mhmm_logprob(data, prior, transmat, mu, Sigma, mixmat)
Daniel@0 2 % LOG_LIK_MHMM Compute the log-likelihood of a dataset using a (mixture of) Gaussians HMM
Daniel@0 3 % [loglik, errors] = log_lik_mhmm(data, prior, transmat, mu, sigma, mixmat)
Daniel@0 4 %
Daniel@0 5 % data{m}(:,t) or data(:,t,m) if all cases have same length
Daniel@0 6 % errors is a list of the cases which received a loglik of -infinity
Daniel@0 7 %
Daniel@0 8 % Set mixmat to ones(Q,1) or omit it if there is only 1 mixture component
Daniel@0 9
Daniel@0 10 Q = length(prior);
Daniel@0 11 if size(mixmat,1) ~= Q % trap old syntax
Daniel@0 12 error('mixmat should be QxM')
Daniel@0 13 end
Daniel@0 14 if nargin < 6, mixmat = ones(Q,1); end
Daniel@0 15
Daniel@0 16 if ~iscell(data)
Daniel@0 17 data = num2cell(data, [1 2]); % each elt of the 3rd dim gets its own cell
Daniel@0 18 end
Daniel@0 19 ncases = length(data);
Daniel@0 20
Daniel@0 21 loglik = 0;
Daniel@0 22 errors = [];
Daniel@0 23 for m=1:ncases
Daniel@0 24 obslik = mixgauss_prob(data{m}, mu, Sigma, mixmat);
Daniel@0 25 [alpha, beta, gamma, ll] = fwdback(prior, transmat, obslik, 'fwd_only', 1);
Daniel@0 26 if ll==-inf
Daniel@0 27 errors = [errors m];
Daniel@0 28 end
Daniel@0 29 loglik = loglik + ll;
Daniel@0 30 end