comparison toolboxes/FullBNT-1.0.7/bnt/examples/dynamic/HHMM/remove_hhmm_end_state.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function [transprob, termprob] = remove_hhmm_end_state(A)
2 % REMOVE_END_STATE Infer transition and termination probabilities from automaton with an end state
3 % [transprob, termprob] = remove_end_state(A)
4 %
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
6 % This implements the equation in footnote 3 of my NIPS 01 paper,
7 % transprob(i,k,j) = \tilde{A}_k(i,j)
8 % termprob(k,j) = \tau_k(j)
9 %
10 % For the top level, the k index is missing.
11
12 Q = size(A,1);
13 toplevel = (ndims(A)==2);
14 if toplevel
15 Qk = 1;
16 A = reshape(A, [Q 1 Q+1]);
17 else
18 Qk = size(A, 2);
19 end
20
21 transprob = A(:, :, 1:Q);
22 term = A(:,:,Q+1)'; % term(k,j) = P(Qj -> end | k)
23 termprob = term;
24 %termprob = zeros(Qk, Q, 2);
25 %termprob(:,:,2) = term;
26 %termprob(:,:,1) = 1-term;
27
28 for k=1:Qk
29 for i=1:Q
30 for j=1:Q
31 denom = (1-termprob(k,i));
32 denom = denom + (denom==0)*eps;
33 transprob(i,k,j) = transprob(i,k,j) / denom;
34 end
35 end
36 end
37
38 if toplevel
39 termprob = squeeze(termprob);
40 transprob = squeeze(transprob);
41 end