annotate toolboxes/FullBNT-1.0.7/bnt/examples/dynamic/HHMM/add_hhmm_end_state.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 function A = add_hhmm_end_state(transprob, termprob)
Daniel@0 2 % ADD_HMM_END_STATE Combine trans and term probs into transmat for automaton with an end state
Daniel@0 3 % function A = add_hhmm_end_state(transprob, termprob)
Daniel@0 4 %
Daniel@0 5 % A(i,k,j) = Pr( i->j | Qps=k), where i in 1:Q, j in 1:(Q+1), and Q+1 is the end state
Daniel@0 6 % This implements the equation in sec 4.6 of my tech report, where
Daniel@0 7 % transprob(i,k,j) = \tilde{A}_k(i,j), termprob(k,j) = \tau_k(j)
Daniel@0 8 %
Daniel@0 9 % For the top level, the k index is missing.
Daniel@0 10
Daniel@0 11 Q = size(transprob,1);
Daniel@0 12 toplevel = (ndims(transprob)==2);
Daniel@0 13 if toplevel
Daniel@0 14 Qk = 1;
Daniel@0 15 transprob = reshape(transprob, [Q 1 Q]);
Daniel@0 16 termprob = reshape(termprob, [1 Q]);
Daniel@0 17 else
Daniel@0 18 Qk = size(transprob, 2);
Daniel@0 19 end
Daniel@0 20
Daniel@0 21 A = zeros(Q, Qk, Q+1);
Daniel@0 22 A(:,:,Q+1) = termprob';
Daniel@0 23
Daniel@0 24 for k=1:Qk
Daniel@0 25 for i=1:Q
Daniel@0 26 for j=1:Q
Daniel@0 27 A(i,k,j) = transprob(i,k,j) * (1-termprob(k,i));
Daniel@0 28 end
Daniel@0 29 end
Daniel@0 30 end
Daniel@0 31
Daniel@0 32 if toplevel
Daniel@0 33 A = squeeze(A);
Daniel@0 34 end