diff toolboxes/FullBNT-1.0.7/HMM/dhmm_em_demo.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/toolboxes/FullBNT-1.0.7/HMM/dhmm_em_demo.m	Tue Feb 10 15:05:51 2015 +0000
@@ -0,0 +1,25 @@
+O = 3;
+Q = 2;
+
+% "true" parameters
+prior0 = normalise(rand(Q,1));
+transmat0 = mk_stochastic(rand(Q,Q));
+obsmat0 = mk_stochastic(rand(Q,O));
+
+% training data
+T = 5;
+nex = 10;
+data = dhmm_sample(prior0, transmat0, obsmat0, T, nex);
+
+% initial guess of parameters
+prior1 = normalise(rand(Q,1));
+transmat1 = mk_stochastic(rand(Q,Q));
+obsmat1 = mk_stochastic(rand(Q,O));
+
+% improve guess of parameters using EM
+[LL, prior2, transmat2, obsmat2] = dhmm_em(data, prior1, transmat1, obsmat1, 'max_iter', 5);
+LL
+
+% use model to compute log likelihood
+loglik = dhmm_logprob(data, prior2, transmat2, obsmat2)
+% log lik is slightly different than LL(end), since it is computed after the final M step