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