annotate toolboxes/FullBNT-1.0.7/HMM/mhmm_em_demo.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 if 1
wolffd@0 2 O = 4;
wolffd@0 3 T = 10;
wolffd@0 4 nex = 50;
wolffd@0 5 M = 2;
wolffd@0 6 Q = 3;
wolffd@0 7 else
wolffd@0 8 O = 8; %Number of coefficients in a vector
wolffd@0 9 T = 420; %Number of vectors in a sequence
wolffd@0 10 nex = 1; %Number of sequences
wolffd@0 11 M = 1; %Number of mixtures
wolffd@0 12 Q = 6; %Number of states
wolffd@0 13 end
wolffd@0 14 cov_type = 'full';
wolffd@0 15
wolffd@0 16 data = randn(O,T,nex);
wolffd@0 17
wolffd@0 18 % initial guess of parameters
wolffd@0 19 prior0 = normalise(rand(Q,1));
wolffd@0 20 transmat0 = mk_stochastic(rand(Q,Q));
wolffd@0 21
wolffd@0 22 if 0
wolffd@0 23 Sigma0 = repmat(eye(O), [1 1 Q M]);
wolffd@0 24 % Initialize each mean to a random data point
wolffd@0 25 indices = randperm(T*nex);
wolffd@0 26 mu0 = reshape(data(:,indices(1:(Q*M))), [O Q M]);
wolffd@0 27 mixmat0 = mk_stochastic(rand(Q,M));
wolffd@0 28 else
wolffd@0 29 [mu0, Sigma0] = mixgauss_init(Q*M, data, cov_type);
wolffd@0 30 mu0 = reshape(mu0, [O Q M]);
wolffd@0 31 Sigma0 = reshape(Sigma0, [O O Q M]);
wolffd@0 32 mixmat0 = mk_stochastic(rand(Q,M));
wolffd@0 33 end
wolffd@0 34
wolffd@0 35 [LL, prior1, transmat1, mu1, Sigma1, mixmat1] = ...
wolffd@0 36 mhmm_em(data, prior0, transmat0, mu0, Sigma0, mixmat0, 'max_iter', 5);
wolffd@0 37
wolffd@0 38
wolffd@0 39 loglik = mhmm_logprob(data, prior1, transmat1, mu1, Sigma1, mixmat1);
wolffd@0 40