comparison toolboxes/FullBNT-1.0.7/bnt/examples/static/Models/mk_hmm_bnet.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 bnet = mk_hmm_bnet(T, Q, O, cts_obs, param_tying)
2 % MK_HMM_BNET Make a (static) bnet to represent a hidden Markov model
3 % bnet = mk_hmm_bnet(T, Q, O, cts_obs, param_tying)
4 %
5 % T = num time slices
6 % Q = num hidden states
7 % O = size of the observed node (num discrete values or length of vector)
8 % cts_obs - 1 means the observed node is a continuous-valued vector, 0 means it's discrete
9 % param_tying - 1 means we create 3 CPDs, 0 means we create 1 CPD per node
10
11 N = 2*T;
12 dag = zeros(N);
13 %hnodes = 1:2:2*T;
14 hnodes = 1:T;
15 for i=1:T-1
16 dag(hnodes(i), hnodes(i+1))=1;
17 end
18 %onodes = 2:2:2*T;
19 onodes = T+1:2*T;
20 for i=1:T
21 dag(hnodes(i), onodes(i)) = 1;
22 end
23
24 if cts_obs
25 dnodes = hnodes;
26 else
27 dnodes = 1:N;
28 end
29 ns = ones(1,N);
30 ns(hnodes) = Q;
31 ns(onodes) = O;
32
33 if param_tying
34 H1class = 1; Hclass = 2; Oclass = 3;
35 eclass = ones(1,N);
36 eclass(hnodes(2:end)) = Hclass;
37 eclass(hnodes(1)) = H1class;
38 eclass(onodes) = Oclass;
39 else
40 eclass = 1:N;
41 end
42
43 bnet = mk_bnet(dag, ns, 'observed', onodes, 'discrete', dnodes, 'equiv_class', eclass);
44
45 hnodes = mysetdiff(1:N, onodes);
46 if ~param_tying
47 for i=hnodes(:)'
48 bnet.CPD{i} = tabular_CPD(bnet, i);
49 end
50 if cts_obs
51 for i=onodes(:)'
52 bnet.CPD{i} = gaussian_CPD(bnet, i);
53 end
54 else
55 for i=onodes(:)'
56 bnet.CPD{i} = tabular_CPD(bnet, i);
57 end
58 end
59 else
60 bnet.CPD{H1class} = tabular_CPD(bnet, hnodes(1)); % prior
61 bnet.CPD{Hclass} = tabular_CPD(bnet, hnodes(2)); % transition matrix
62 if cts_obs
63 bnet.CPD{Oclass} = gaussian_CPD(bnet, onodes(1));
64 else
65 bnet.CPD{Oclass} = tabular_CPD(bnet, onodes(1));
66 end
67 end