about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/mk_hhmm_topo_F1.m
blob: 2fc5f9124ce844559a0c4d1f2b41d00545c0f282 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function [intra, inter, Qnodes, Fnodes, Onode] = mk_hhmm_topo_F1(D, all_Q_to_Qs, Ops)
% MK_HHMM_TOPO Make Hierarchical HMM topology assuming level 1 can finish 
% function [intra, inter, Qnodes, Fnodes, Onode] = mk_hhmm_topo(D, all_Q_to_Qs, Ops, F1)
%
% D is the depth of the hierarchy
% If all_Q_to_Qs = 1, level i connects to all levels below, else just to i+1 [0]
% Ops are the Q parents of the observed node [Qnodes(end)]
% If F1=1, level 1 can finish (restart), else there is no F1->Q1 arc [0]

Qnodes = 1:D;

if nargin < 2, all_Q_to_Qs = 1; end
if nargin < 3, Ops = Qnodes(D); end
if nargin < 4, F1 = 0; end

if F1
  Fnodes = 2*D:-1:D+1; % must number from bottom to top
  Onode = 2*D+1;
  ss = 2*D+1;
else
  Fnodes = (2*D)-1:-1:D+1;
  Onode = 2*D;
  ss = 2*D;
end

intra = zeros(ss);
intra(Ops, Onode) = 1;
for d=1:D-1
  if all_Q_to_Qs
    intra(Qnodes(d), Qnodes(d+1:end)) = 1;
  else
    intra(Qnodes(d), Qnodes(d+1)) = 1;
  end
end
for d=D:-1:3
  intra(Fnodes(d), Fnodes(d-1)) = 1;
end
if F1
  intra(Fnodes(2), Fnodes(1)) = 1;
end
if all_Q_to_Qs
  for d=1:D
    intra(Qnodes(d), Fnodes(d:end)) = 1;
  end
else
  for d=1:D
    if d < D
      intra(Qnodes(d), Fnodes([d d+1])) = 1;
    else
      intra(Qnodes(d), Fnodes(d)) = 1;
    end
  end
end

inter = zeros(ss);
for d=1:D
  inter(Qnodes(d), Qnodes(d)) = 1;
end
for d=1:D
  if d==1
    inter(Fnodes(d), Qnodes(d)) = 1;
  else
    inter(Fnodes(d), Qnodes([d-1 d])) = 1;
  end
end