comparison toolboxes/FullBNT-1.0.7/bnt/examples/dynamic/HHMM/Old/mk_arrow_alpha_hhmm3.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 % Make the following HHMM
2 %
3 % LH RH
4 % / \
5 % / \
6 % LR -> UD -> RL -> DU RL -> UD -> LR -> DU
7 % \
8 % \
9 % Q1 -> Q2
10 %
11 % where level 1 is fully interconnected (not shown)
12 % level 2 is left-right
13 % and each model at level 3 is a 2 state LR shared HMM
14
15 Qsizes = [2 4 2];
16 D = 3;
17
18 % LEVEL 1
19
20 startprob1 = 'ergodic';
21 transprob1 = 'ergodic';
22
23
24 % LEVEL 2
25
26 startprob = zeros(2, 4);
27 % Q1 Q2
28 startprob(1, 1) = 1;
29 startprob(2, 3) = 1;
30
31 transprob = zeros(2, 4, 4);
32 transprob(1,:,:) = [0 1 0 0
33 0 0 1 0
34 0 0 0 1
35 0 0 0 1];
36 transprob(2,:,:) = [0 0 0 1
37 1 0 0 0
38 0 1 0 0
39 0 0 0 1];
40
41 Q2args = {'startprob', startprob, 'transprob', transprob};
42
43 % always terminate in state 4 (default)
44 % F2args
45
46 % LEVEL 3
47
48 % Defaults are fine: always start in state 1, left-right model, finish in state 2
49
50
51 % OBS LEVEl
52
53 chars = ['L', 'l', 'U', 'u', 'R', 'r', 'D', 'd'];
54 Osize = length(chars);
55
56 obsprob = zeros([4 2 Osize]);
57 % Q2 Q3 O
58 obsprob(1, 1, find(chars == 'L')) = 1.0;
59 obsprob(1, 2, find(chars == 'l')) = 1.0;
60
61 obsprob(2, 1, find(chars == 'U')) = 1.0;
62 obsprob(2, 2, find(chars == 'u')) = 1.0;
63
64 obsprob(3, 1, find(chars == 'R')) = 1.0;
65 obsprob(3, 2, find(chars == 'r')) = 1.0;
66
67 obsprob(4, 1, find(chars == 'D')) = 1.0;
68 obsprob(4, 2, find(chars == 'd')) = 1.0;
69
70 Oargs = {'CPT', obsprob};
71
72
73 bnet = mk_hhmm3('Qsizes', Qsizes, 'Osize', Osize', 'discrete_obs', 1, 'Oargs', Oargs, 'Q1args', Q1args, 'Q2args', Q2args);
74
75 T = 20;
76 usecell = 0;
77 evidence = sample_dbn(bnet, T, usecell);
78 %chars(evidence(end,:))
79
80 Q1 = 1; Q2 = 2; Q3 = 3; F3 = 4; F2 = 5; obs = 6;
81 Qnodes = [Q1 Q2 Q3]; Fnodes = [F2 F3];
82
83 pretty_print_hhmm_parse(evidence, Qnodes, Fnodes, obs, chars);
84
85 eclass = bnet.equiv_class;
86 S=struct(bnet.CPD{eclass(Q2,2)})