annotate toolboxes/FullBNT-1.0.7/bnt/examples/dynamic/HHMM/abcd_hhmm.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 % Make the HHMM in Figure 1 of the NIPS'01 paper
Daniel@0 2
Daniel@0 3 Qsize = [2 3 2];
Daniel@0 4 Qnodes = 1:3;
Daniel@0 5 D = 3;
Daniel@0 6 transprob = cell(1,D);
Daniel@0 7 termprob = cell(1,D);
Daniel@0 8 startprob = cell(1,D);
Daniel@0 9 clear A;
Daniel@0 10
Daniel@0 11 % transprob{d}(i,k,j), transprob{1}(i,j)
Daniel@0 12 % termprob{d}(k,j), termprob{1}(1,j)
Daniel@0 13 % startprob{d}(k,j), startprob{1}(1,j)
Daniel@0 14
Daniel@0 15
Daniel@0 16 % LEVEL 1
Daniel@0 17
Daniel@0 18 % 1 2 e
Daniel@0 19 A{1} = [0 0 1;
Daniel@0 20 0 0 1];
Daniel@0 21 [transprob{1}, termprob{1}] = remove_hhmm_end_state(A{1});
Daniel@0 22 startprob{1} = [0.5 0.5];
Daniel@0 23
Daniel@0 24 % LEVEL 2
Daniel@0 25 A{2} = zeros(Qsize(2), Qsize(1), Qsize(2)+1);
Daniel@0 26
Daniel@0 27 % 1 2 3 e
Daniel@0 28 A{2}(:,1,:) = [0 1 0 0 % Q1=1 => model below state 0
Daniel@0 29 0 0 1 0
Daniel@0 30 0 0 0 1];
Daniel@0 31
Daniel@0 32 % 1 2 3 e
Daniel@0 33 A{2}(:,2,:) = [0 1 0 0 % Q1=2 => model below state 1
Daniel@0 34 0 0 1 0
Daniel@0 35 0 0 0 1];
Daniel@0 36
Daniel@0 37 [transprob{2}, termprob{2}] = remove_hhmm_end_state(A{2});
Daniel@0 38
Daniel@0 39 % always enter level 2 in state 1
Daniel@0 40 startprob{2} = [1 0 0
Daniel@0 41 1 0 0];
Daniel@0 42
Daniel@0 43 % LEVEL 3
Daniel@0 44
Daniel@0 45 A{3} = zeros([Qsize(3) Qsize(2) Qsize(3)+1]);
Daniel@0 46 endstate = Qsize(3)+1;
Daniel@0 47 % Qt-1(3) Qt(2) Qt(3)
Daniel@0 48 % 1 2 e
Daniel@0 49 A{3}(1, 1, endstate) = 1.0; % Q2=1 => model below state 2/5
Daniel@0 50 A{3}(:, 2, :) = [0.0 1.0 0.0 % Q2=2 => model below state 3/6
Daniel@0 51 0.5 0.0 0.5];
Daniel@0 52 A{3}(1, 3, endstate) = 1.0; % Q2=3 => model below state 4/7
Daniel@0 53
Daniel@0 54 [transprob{3}, termprob{3}] = remove_hhmm_end_state(A{3});
Daniel@0 55
Daniel@0 56 startprob{3} = 'leftstart';
Daniel@0 57
Daniel@0 58
Daniel@0 59
Daniel@0 60 % OBS LEVEl
Daniel@0 61
Daniel@0 62 chars = ['a', 'b', 'c', 'd', 'x', 'y'];
Daniel@0 63 Osize = length(chars);
Daniel@0 64
Daniel@0 65 obsprob = zeros([Qsize Osize]);
Daniel@0 66 % 1 2 3 O
Daniel@0 67 obsprob(1,1,1,find(chars == 'a')) = 1.0;
Daniel@0 68
Daniel@0 69 obsprob(1,2,1,find(chars == 'x')) = 1.0;
Daniel@0 70 obsprob(1,2,2,find(chars == 'y')) = 1.0;
Daniel@0 71
Daniel@0 72 obsprob(1,3,1,find(chars == 'b')) = 1.0;
Daniel@0 73
Daniel@0 74 obsprob(2,1,1,find(chars == 'c')) = 1.0;
Daniel@0 75
Daniel@0 76 obsprob(2,2,1,find(chars == 'x')) = 1.0;
Daniel@0 77 obsprob(2,2,2,find(chars == 'y')) = 1.0;
Daniel@0 78
Daniel@0 79 obsprob(2,3,1,find(chars == 'd')) = 1.0;
Daniel@0 80
Daniel@0 81 Oargs = {'CPT', obsprob};
Daniel@0 82
Daniel@0 83 bnet = mk_hhmm('Qsizes', Qsize, 'Osize', Osize, 'discrete_obs', 1, ...
Daniel@0 84 'Oargs', Oargs, 'Ops', Qnodes(1:3), ...
Daniel@0 85 'startprob', startprob, 'transprob', transprob, 'termprob', termprob);
Daniel@0 86
Daniel@0 87
Daniel@0 88 Q1 = 1; Q2 = 2; Q3 = 3; F3 = 4; F2 = 5; Onode = 6;
Daniel@0 89 Qnodes = [Q1 Q2 Q3]; Fnodes = [F2 F3];
Daniel@0 90
Daniel@0 91 for seqi=1:3
Daniel@0 92 evidence = sample_dbn(bnet, 'stop_test', 'is_F2_true_D3');
Daniel@0 93 ev = cell2num(evidence);
Daniel@0 94 chars(ev(end,:))
Daniel@0 95 %T = size(evidence, 2)
Daniel@0 96 %pretty_print_hhmm_parse(evidence, Qnodes, Fnodes, Onode, chars);
Daniel@0 97 end