annotate toolboxes/FullBNT-1.0.7/docs/dbn_hmm_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 Example due to Wang Hee Lin" <engp1622@nus.edu.sg
wolffd@0 2
wolffd@0 3
wolffd@0 4 intra = zeros(2);
wolffd@0 5 intra(1,2) = 1;
wolffd@0 6 inter = zeros(2);
wolffd@0 7 inter(1,1) = 1;
wolffd@0 8
wolffd@0 9 Q = 2; % num hidden states
wolffd@0 10 O = 2; % num observable symbols
wolffd@0 11 ns = [Q O];%number of states
wolffd@0 12 dnodes = 1:2;
wolffd@0 13 %onodes = [1:2]; % only possible with jtree, not hmm
wolffd@0 14 onodes = [2];
wolffd@0 15 bnet = mk_dbn(intra, inter, ns, 'discrete', dnodes, 'observed', onodes);
wolffd@0 16 for i=1:4
wolffd@0 17 bnet.CPD{i} = tabular_CPD(bnet, i);
wolffd@0 18 end
wolffd@0 19
wolffd@0 20 prior0 = normalise(rand(Q,1));
wolffd@0 21 transmat0 = mk_stochastic(rand(Q,Q));
wolffd@0 22 obsmat0 = mk_stochastic(rand(Q,O));
wolffd@0 23
wolffd@0 24 %engine = smoother_engine(hmm_2TBN_inf_engine(bnet));
wolffd@0 25 engine = smoother_engine(jtree_2TBN_inf_engine(bnet));
wolffd@0 26
wolffd@0 27 ss = 2;%slice size(ss)
wolffd@0 28 ncases = 10;%number of examples
wolffd@0 29 T=10;
wolffd@0 30 max_iter=2;%iterations for EM
wolffd@0 31 cases = cell(1, ncases);
wolffd@0 32 for i=1:ncases
wolffd@0 33 ev = sample_dbn(bnet, T);
wolffd@0 34 cases{i} = cell(ss,T);
wolffd@0 35 cases{i}(onodes,:) = ev(onodes, :);
wolffd@0 36 end
wolffd@0 37 [bnet2, LLtrace] = learn_params_dbn_em(engine, cases, 'max_iter', 4);