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