Daniel@0: % Make the HHMM in Figure 1 of the NIPS'01 paper Daniel@0: Daniel@0: Qsize = [2 3 2]; Daniel@0: Qnodes = 1:3; Daniel@0: D = 3; Daniel@0: transprob = cell(1,D); Daniel@0: termprob = cell(1,D); Daniel@0: startprob = cell(1,D); Daniel@0: clear A; Daniel@0: Daniel@0: % transprob{d}(i,k,j), transprob{1}(i,j) Daniel@0: % termprob{d}(k,j), termprob{1}(1,j) Daniel@0: % startprob{d}(k,j), startprob{1}(1,j) Daniel@0: Daniel@0: Daniel@0: % LEVEL 1 Daniel@0: Daniel@0: % 1 2 e Daniel@0: A{1} = [0 0 1; Daniel@0: 0 0 1]; Daniel@0: [transprob{1}, termprob{1}] = remove_hhmm_end_state(A{1}); Daniel@0: startprob{1} = [0.5 0.5]; Daniel@0: Daniel@0: % LEVEL 2 Daniel@0: A{2} = zeros(Qsize(2), Qsize(1), Qsize(2)+1); Daniel@0: Daniel@0: % 1 2 3 e Daniel@0: A{2}(:,1,:) = [0 1 0 0 % Q1=1 => model below state 0 Daniel@0: 0 0 1 0 Daniel@0: 0 0 0 1]; Daniel@0: Daniel@0: % 1 2 3 e Daniel@0: A{2}(:,2,:) = [0 1 0 0 % Q1=2 => model below state 1 Daniel@0: 0 0 1 0 Daniel@0: 0 0 0 1]; Daniel@0: Daniel@0: [transprob{2}, termprob{2}] = remove_hhmm_end_state(A{2}); Daniel@0: Daniel@0: % always enter level 2 in state 1 Daniel@0: startprob{2} = [1 0 0 Daniel@0: 1 0 0]; Daniel@0: Daniel@0: % LEVEL 3 Daniel@0: Daniel@0: A{3} = zeros([Qsize(3) Qsize(2) Qsize(3)+1]); Daniel@0: endstate = Qsize(3)+1; Daniel@0: % Qt-1(3) Qt(2) Qt(3) Daniel@0: % 1 2 e Daniel@0: A{3}(1, 1, endstate) = 1.0; % Q2=1 => model below state 2/5 Daniel@0: A{3}(:, 2, :) = [0.0 1.0 0.0 % Q2=2 => model below state 3/6 Daniel@0: 0.5 0.0 0.5]; Daniel@0: A{3}(1, 3, endstate) = 1.0; % Q2=3 => model below state 4/7 Daniel@0: Daniel@0: [transprob{3}, termprob{3}] = remove_hhmm_end_state(A{3}); Daniel@0: Daniel@0: startprob{3} = 'leftstart'; Daniel@0: Daniel@0: Daniel@0: Daniel@0: % OBS LEVEl Daniel@0: Daniel@0: chars = ['a', 'b', 'c', 'd', 'x', 'y']; Daniel@0: Osize = length(chars); Daniel@0: Daniel@0: obsprob = zeros([Qsize Osize]); Daniel@0: % 1 2 3 O Daniel@0: obsprob(1,1,1,find(chars == 'a')) = 1.0; Daniel@0: Daniel@0: obsprob(1,2,1,find(chars == 'x')) = 1.0; Daniel@0: obsprob(1,2,2,find(chars == 'y')) = 1.0; Daniel@0: Daniel@0: obsprob(1,3,1,find(chars == 'b')) = 1.0; Daniel@0: Daniel@0: obsprob(2,1,1,find(chars == 'c')) = 1.0; Daniel@0: Daniel@0: obsprob(2,2,1,find(chars == 'x')) = 1.0; Daniel@0: obsprob(2,2,2,find(chars == 'y')) = 1.0; Daniel@0: Daniel@0: obsprob(2,3,1,find(chars == 'd')) = 1.0; Daniel@0: Daniel@0: Oargs = {'CPT', obsprob}; Daniel@0: Daniel@0: bnet = mk_hhmm('Qsizes', Qsize, 'Osize', Osize, 'discrete_obs', 1, ... Daniel@0: 'Oargs', Oargs, 'Ops', Qnodes(1:3), ... Daniel@0: 'startprob', startprob, 'transprob', transprob, 'termprob', termprob); Daniel@0: Daniel@0: Daniel@0: Q1 = 1; Q2 = 2; Q3 = 3; F3 = 4; F2 = 5; Onode = 6; Daniel@0: Qnodes = [Q1 Q2 Q3]; Fnodes = [F2 F3]; Daniel@0: Daniel@0: for seqi=1:3 Daniel@0: evidence = sample_dbn(bnet, 'stop_test', 'is_F2_true_D3'); Daniel@0: ev = cell2num(evidence); Daniel@0: chars(ev(end,:)) Daniel@0: %T = size(evidence, 2) Daniel@0: %pretty_print_hhmm_parse(evidence, Qnodes, Fnodes, Onode, chars); Daniel@0: end