comparison toolboxes/FullBNT-1.0.7/bnt/examples/dynamic/jtree_clq_test.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 % Construct various DBNs and examine their clique structure.
2 % This was used to generate various figures in chap 3-4 of my thesis.
3
4 % Examine the cliques in the unrolled mildew net
5
6 %dbn = mk_mildew_dbn;
7 dbn = mk_chmm(4);
8 ss = dbn.nnodes_per_slice;
9 T = 7;
10 N = ss*T;
11 bnet = dbn_to_bnet(dbn, T);
12
13 constrained = 0;
14 if constrained
15 stages = num2cell(unroll_set(1:ss, ss, T), 1);
16 else
17 stages = { 1:N; };
18 end
19 clusters = {};
20 %[jtree, root, cliques, B, w, elim_order, moral_edges, fill_in_edges] = ...
21 % dag_to_jtree(bnet, bnet.observed, stages, clusters);
22 [jtree, root, cliques] = graph_to_jtree(moralize(bnet.dag), ones(1,N), stages, clusters);
23
24 flip=1;
25 clf;[dummyx, dummyy, h] = draw_dbn(dbn.intra, dbn.inter, flip, T, -1);
26 dir = '/home/eecs/murphyk/WP/Thesis/Figures/Inf/MildewUnrolled';
27 mk_ps_from_clqs(dbn, T, cliques, [])
28 %mk_collage_from_clqs(dir, cliques)
29
30
31 % Examine the cliques in the cascade DBN
32
33 % A-A
34 % \
35 % B B
36 % \
37 % C C
38 % \
39 % D D
40 ss = 4;
41 intra = zeros(ss);
42 inter = zeros(ss);
43 inter(1, [1 2])=1;
44 for i=2:ss-1
45 inter(i,i+1)=1;
46 end
47
48
49 % 2 coupled HMMs 1,3 and 2,4
50 ss = 4;
51 intra = zeros(ss);
52 inter = zeros(ss); % no persistent edges
53 %inter = diag(ones(ss,1)); % persitence edges
54 inter(1,3)=1; inter(3,1)=1;
55 inter(2,4)=1; inter(4,2)=1;
56
57 %bnet = mk_fhmm(3);
58 bnet = mk_chmm(4);
59 intra = bnet.intra;
60 inter = bnet.inter;
61
62 clqs = compute_minimal_interface(intra, inter);
63 celldisp(clqs)
64
65
66
67
68 % A A
69 % \
70 % B B
71 % \
72 % C C
73 % \
74 % D-D
75 ss = 4;
76 intra = zeros(ss);
77 inter = zeros(ss);
78 for i=1:ss-1
79 inter(i,i+1)=1;
80 end
81 inter(4,4)=1;
82
83
84
85 ns = 2*ones(1,ss);
86 dbn = mk_dbn(intra, inter, ns);
87 for i=2*ss
88 dbn.CPD{i} = tabular_CPD(bnet, i);
89 end
90
91 T = 4;
92 N = ss*T;
93 bnet = dbn_to_bnet(dbn, T);
94
95 constrained = 1;
96 if constrained
97 % elim first 3 slices first in any order
98 stages = {1:12, 13:16};
99 %stages = num2cell(unroll_set(1:ss, ss, T), 1);
100 else
101 stages = { 1:N; };
102 end
103 clusters = {};
104 %[jtree, root, cliques, B, w, elim_order, moral_edges, fill_in_edges] = ...
105 % dag_to_jtree(bnet, bnet.observed, stages, clusters);
106 [jtree, root, cliques] = graph_to_jtree(moralize(bnet.dag), ones(1,N), stages, clusters);
107
108
109
110
111
112 % Examine the cliques in the 1.5 slice DBN
113
114 %dbn = mk_mildew_dbn;
115 dbn = mk_water_dbn;
116 %dbn = mk_bat_dbn;
117 ss = dbn.nnodes_per_slice;
118 int = compute_fwd_interface(dbn);
119 bnet15 = mk_slice_and_half_dbn(dbn, int);
120 N = length(bnet15.dag);
121 stages = {1:N};
122
123 % bat
124 %cl1 = [16 17 19 7 14];
125 %cl2 = [27 25 21 23 20];
126 %clusters = {cl1, cl2, cl1+ss, cl2+ss};
127
128 % water
129 %cl1 = 1:2; cl2 = 3:6; cl3 = 7:8;
130 %clusters = {cl1, cl2, cl3, cl1+ss, cl2+ss, cl3+ss};
131
132 %clusters = {};
133 clusters = {int, int+ss};
134 %[jtree, root, cliques, B, w, elim_order, moral_edges, fill_in_edges] = ...
135 % dag_to_jtree(bnet15, bnet.observed, stages, clusters);
136 [jtree, root, cliques] = graph_to_jtree(moralize(bnet15.dag), ones(1,N), stages, clusters);
137
138 clq_len = [];
139 for c=1:length(cliques)
140 clq_len(c) = length(cliques{c});
141 end
142 hist(clq_len, 1:max(clq_len));
143 h=hist(clq_len, 1:max(clq_len));
144 axis([1 max(clq_len)+1 0 max(h)+1])
145 xlabel('clique size','fontsize',16)
146 ylabel('number','fontsize',16)
147
148
149
150