annotate toolboxes/FullBNT-1.0.7/bnt/examples/dynamic/HHMM/remove_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 [transprob, termprob] = remove_hhmm_end_state(A)
Daniel@0 2 % REMOVE_END_STATE Infer transition and termination probabilities from automaton with an end state
Daniel@0 3 % [transprob, termprob] = remove_end_state(A)
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 footnote 3 of my NIPS 01 paper,
Daniel@0 7 % transprob(i,k,j) = \tilde{A}_k(i,j)
Daniel@0 8 % termprob(k,j) = \tau_k(j)
Daniel@0 9 %
Daniel@0 10 % For the top level, the k index is missing.
Daniel@0 11
Daniel@0 12 Q = size(A,1);
Daniel@0 13 toplevel = (ndims(A)==2);
Daniel@0 14 if toplevel
Daniel@0 15 Qk = 1;
Daniel@0 16 A = reshape(A, [Q 1 Q+1]);
Daniel@0 17 else
Daniel@0 18 Qk = size(A, 2);
Daniel@0 19 end
Daniel@0 20
Daniel@0 21 transprob = A(:, :, 1:Q);
Daniel@0 22 term = A(:,:,Q+1)'; % term(k,j) = P(Qj -> end | k)
Daniel@0 23 termprob = term;
Daniel@0 24 %termprob = zeros(Qk, Q, 2);
Daniel@0 25 %termprob(:,:,2) = term;
Daniel@0 26 %termprob(:,:,1) = 1-term;
Daniel@0 27
Daniel@0 28 for k=1:Qk
Daniel@0 29 for i=1:Q
Daniel@0 30 for j=1:Q
Daniel@0 31 denom = (1-termprob(k,i));
Daniel@0 32 denom = denom + (denom==0)*eps;
Daniel@0 33 transprob(i,k,j) = transprob(i,k,j) / denom;
Daniel@0 34 end
Daniel@0 35 end
Daniel@0 36 end
Daniel@0 37
Daniel@0 38 if toplevel
Daniel@0 39 termprob = squeeze(termprob);
Daniel@0 40 transprob = squeeze(transprob);
Daniel@0 41 end