Daniel@0: function A = add_hhmm_end_state(transprob, termprob) Daniel@0: % ADD_HMM_END_STATE Combine trans and term probs into transmat for automaton with an end state Daniel@0: % function A = add_hhmm_end_state(transprob, termprob) Daniel@0: % Daniel@0: % 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: % This implements the equation in sec 4.6 of my tech report, where Daniel@0: % transprob(i,k,j) = \tilde{A}_k(i,j), termprob(k,j) = \tau_k(j) Daniel@0: % Daniel@0: % For the top level, the k index is missing. Daniel@0: Daniel@0: Q = size(transprob,1); Daniel@0: toplevel = (ndims(transprob)==2); Daniel@0: if toplevel Daniel@0: Qk = 1; Daniel@0: transprob = reshape(transprob, [Q 1 Q]); Daniel@0: termprob = reshape(termprob, [1 Q]); Daniel@0: else Daniel@0: Qk = size(transprob, 2); Daniel@0: end Daniel@0: Daniel@0: A = zeros(Q, Qk, Q+1); Daniel@0: A(:,:,Q+1) = termprob'; Daniel@0: Daniel@0: for k=1:Qk Daniel@0: for i=1:Q Daniel@0: for j=1:Q Daniel@0: A(i,k,j) = transprob(i,k,j) * (1-termprob(k,i)); Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: if toplevel Daniel@0: A = squeeze(A); Daniel@0: end