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