Daniel@0
|
1 function [intra, inter, Qnodes, Fnodes, Onode] = mk_hhmm_topo(D, all_Q_to_Qs, Ops, F1)
|
Daniel@0
|
2 % MK_HHMM_TOPO Make Hierarchical HMM topology
|
Daniel@0
|
3 % function [intra, inter, Qnodes, Fnodes, Onode] = mk_hhmm_topo(D, all_Q_to_Qs, Ops, F1)
|
Daniel@0
|
4 %
|
Daniel@0
|
5 % D is the depth of the hierarchy
|
Daniel@0
|
6 % If all_Q_to_Qs = 1, level i connects to all levels below, else just to i+1 [0]
|
Daniel@0
|
7 % Ops are the Q parents of the observed node [Qnodes(end)]
|
Daniel@0
|
8 % If F1=1, level 1 can finish (restart), else there is no F1->Q1 arc [0]
|
Daniel@0
|
9
|
Daniel@0
|
10 Qnodes = 1:D;
|
Daniel@0
|
11
|
Daniel@0
|
12 if nargin < 2, all_Q_to_Qs = 1; end
|
Daniel@0
|
13 if nargin < 3, Ops = Qnodes(D); end
|
Daniel@0
|
14 if nargin < 4, F1 = 0; end
|
Daniel@0
|
15
|
Daniel@0
|
16 if F1
|
Daniel@0
|
17 Fnodes = 2*D:-1:D+1; % must number from bottom to top
|
Daniel@0
|
18 Onode = 2*D+1;
|
Daniel@0
|
19 ss = 2*D+1;
|
Daniel@0
|
20 else
|
Daniel@0
|
21 Fnodes = [-1 (2*D)-1:-1:D+1]; % Fnodes(1) is a dummy index
|
Daniel@0
|
22 Onode = 2*D;
|
Daniel@0
|
23 ss = 2*D;
|
Daniel@0
|
24 end
|
Daniel@0
|
25
|
Daniel@0
|
26 intra = zeros(ss);
|
Daniel@0
|
27 intra(Ops, Onode) = 1;
|
Daniel@0
|
28 for d=1:D-1
|
Daniel@0
|
29 if all_Q_to_Qs
|
Daniel@0
|
30 intra(Qnodes(d), Qnodes(d+1:end)) = 1;
|
Daniel@0
|
31 else
|
Daniel@0
|
32 intra(Qnodes(d), Qnodes(d+1)) = 1;
|
Daniel@0
|
33 end
|
Daniel@0
|
34 end
|
Daniel@0
|
35 for d=D:-1:3
|
Daniel@0
|
36 intra(Fnodes(d), Fnodes(d-1)) = 1;
|
Daniel@0
|
37 end
|
Daniel@0
|
38 if F1
|
Daniel@0
|
39 intra(Fnodes(2), Fnodes(1)) = 1;
|
Daniel@0
|
40 end
|
Daniel@0
|
41 if all_Q_to_Qs
|
Daniel@0
|
42 if F1
|
Daniel@0
|
43 intra(Qnodes(1), Fnodes(1:end)) = 1;
|
Daniel@0
|
44 else
|
Daniel@0
|
45 intra(Qnodes(1), Fnodes(2:end)) = 1;
|
Daniel@0
|
46 end
|
Daniel@0
|
47 for d=2:D
|
Daniel@0
|
48 intra(Qnodes(d), Fnodes(d:end)) = 1;
|
Daniel@0
|
49 end
|
Daniel@0
|
50 else
|
Daniel@0
|
51 if F1
|
Daniel@0
|
52 intra(Qnodes(1), Fnodes([1 2])) = 1;
|
Daniel@0
|
53 else
|
Daniel@0
|
54 intra(Qnodes(1), Fnodes(2)) = 1;
|
Daniel@0
|
55 end
|
Daniel@0
|
56 for d=2:D-1
|
Daniel@0
|
57 intra(Qnodes(d), Fnodes([d d+1])) = 1;
|
Daniel@0
|
58 end
|
Daniel@0
|
59 intra(Qnodes(D), Fnodes(D)) = 1;
|
Daniel@0
|
60 end
|
Daniel@0
|
61
|
Daniel@0
|
62
|
Daniel@0
|
63 inter = zeros(ss);
|
Daniel@0
|
64 for d=1:D
|
Daniel@0
|
65 inter(Qnodes(d), Qnodes(d)) = 1;
|
Daniel@0
|
66 end
|
Daniel@0
|
67 if F1
|
Daniel@0
|
68 inter(Fnodes(1), Qnodes(1)) = 1;
|
Daniel@0
|
69 end
|
Daniel@0
|
70 for d=2:D
|
Daniel@0
|
71 inter(Fnodes(d), Qnodes([d-1 d])) = 1;
|
Daniel@0
|
72 end
|
Daniel@0
|
73
|
Daniel@0
|
74 if ~F1
|
Daniel@0
|
75 Fnodes = Fnodes(2:end); % strip off dummy -1 term
|
Daniel@0
|
76 end
|