Daniel@0: % Construct various DBNs and examine their clique structure. Daniel@0: % This was used to generate various figures in chap 3-4 of my thesis. Daniel@0: Daniel@0: % Examine the cliques in the unrolled mildew net Daniel@0: Daniel@0: %dbn = mk_mildew_dbn; Daniel@0: dbn = mk_chmm(4); Daniel@0: ss = dbn.nnodes_per_slice; Daniel@0: T = 7; Daniel@0: N = ss*T; Daniel@0: bnet = dbn_to_bnet(dbn, T); Daniel@0: Daniel@0: constrained = 0; Daniel@0: if constrained Daniel@0: stages = num2cell(unroll_set(1:ss, ss, T), 1); Daniel@0: else Daniel@0: stages = { 1:N; }; Daniel@0: end Daniel@0: clusters = {}; Daniel@0: %[jtree, root, cliques, B, w, elim_order, moral_edges, fill_in_edges] = ... Daniel@0: % dag_to_jtree(bnet, bnet.observed, stages, clusters); Daniel@0: [jtree, root, cliques] = graph_to_jtree(moralize(bnet.dag), ones(1,N), stages, clusters); Daniel@0: Daniel@0: flip=1; Daniel@0: clf;[dummyx, dummyy, h] = draw_dbn(dbn.intra, dbn.inter, flip, T, -1); Daniel@0: dir = '/home/eecs/murphyk/WP/Thesis/Figures/Inf/MildewUnrolled'; Daniel@0: mk_ps_from_clqs(dbn, T, cliques, []) Daniel@0: %mk_collage_from_clqs(dir, cliques) Daniel@0: Daniel@0: Daniel@0: % Examine the cliques in the cascade DBN Daniel@0: Daniel@0: % A-A Daniel@0: % \ Daniel@0: % B B Daniel@0: % \ Daniel@0: % C C Daniel@0: % \ Daniel@0: % D D Daniel@0: ss = 4; Daniel@0: intra = zeros(ss); Daniel@0: inter = zeros(ss); Daniel@0: inter(1, [1 2])=1; Daniel@0: for i=2:ss-1 Daniel@0: inter(i,i+1)=1; Daniel@0: end Daniel@0: Daniel@0: Daniel@0: % 2 coupled HMMs 1,3 and 2,4 Daniel@0: ss = 4; Daniel@0: intra = zeros(ss); Daniel@0: inter = zeros(ss); % no persistent edges Daniel@0: %inter = diag(ones(ss,1)); % persitence edges Daniel@0: inter(1,3)=1; inter(3,1)=1; Daniel@0: inter(2,4)=1; inter(4,2)=1; Daniel@0: Daniel@0: %bnet = mk_fhmm(3); Daniel@0: bnet = mk_chmm(4); Daniel@0: intra = bnet.intra; Daniel@0: inter = bnet.inter; Daniel@0: Daniel@0: clqs = compute_minimal_interface(intra, inter); Daniel@0: celldisp(clqs) Daniel@0: Daniel@0: Daniel@0: Daniel@0: Daniel@0: % A A Daniel@0: % \ Daniel@0: % B B Daniel@0: % \ Daniel@0: % C C Daniel@0: % \ Daniel@0: % D-D Daniel@0: ss = 4; Daniel@0: intra = zeros(ss); Daniel@0: inter = zeros(ss); Daniel@0: for i=1:ss-1 Daniel@0: inter(i,i+1)=1; Daniel@0: end Daniel@0: inter(4,4)=1; Daniel@0: Daniel@0: Daniel@0: Daniel@0: ns = 2*ones(1,ss); Daniel@0: dbn = mk_dbn(intra, inter, ns); Daniel@0: for i=2*ss Daniel@0: dbn.CPD{i} = tabular_CPD(bnet, i); Daniel@0: end Daniel@0: Daniel@0: T = 4; Daniel@0: N = ss*T; Daniel@0: bnet = dbn_to_bnet(dbn, T); Daniel@0: Daniel@0: constrained = 1; Daniel@0: if constrained Daniel@0: % elim first 3 slices first in any order Daniel@0: stages = {1:12, 13:16}; Daniel@0: %stages = num2cell(unroll_set(1:ss, ss, T), 1); Daniel@0: else Daniel@0: stages = { 1:N; }; Daniel@0: end Daniel@0: clusters = {}; Daniel@0: %[jtree, root, cliques, B, w, elim_order, moral_edges, fill_in_edges] = ... Daniel@0: % dag_to_jtree(bnet, bnet.observed, stages, clusters); Daniel@0: [jtree, root, cliques] = graph_to_jtree(moralize(bnet.dag), ones(1,N), stages, clusters); Daniel@0: Daniel@0: Daniel@0: Daniel@0: Daniel@0: Daniel@0: % Examine the cliques in the 1.5 slice DBN Daniel@0: Daniel@0: %dbn = mk_mildew_dbn; Daniel@0: dbn = mk_water_dbn; Daniel@0: %dbn = mk_bat_dbn; Daniel@0: ss = dbn.nnodes_per_slice; Daniel@0: int = compute_fwd_interface(dbn); Daniel@0: bnet15 = mk_slice_and_half_dbn(dbn, int); Daniel@0: N = length(bnet15.dag); Daniel@0: stages = {1:N}; Daniel@0: Daniel@0: % bat Daniel@0: %cl1 = [16 17 19 7 14]; Daniel@0: %cl2 = [27 25 21 23 20]; Daniel@0: %clusters = {cl1, cl2, cl1+ss, cl2+ss}; Daniel@0: Daniel@0: % water Daniel@0: %cl1 = 1:2; cl2 = 3:6; cl3 = 7:8; Daniel@0: %clusters = {cl1, cl2, cl3, cl1+ss, cl2+ss, cl3+ss}; Daniel@0: Daniel@0: %clusters = {}; Daniel@0: clusters = {int, int+ss}; Daniel@0: %[jtree, root, cliques, B, w, elim_order, moral_edges, fill_in_edges] = ... Daniel@0: % dag_to_jtree(bnet15, bnet.observed, stages, clusters); Daniel@0: [jtree, root, cliques] = graph_to_jtree(moralize(bnet15.dag), ones(1,N), stages, clusters); Daniel@0: Daniel@0: clq_len = []; Daniel@0: for c=1:length(cliques) Daniel@0: clq_len(c) = length(cliques{c}); Daniel@0: end Daniel@0: hist(clq_len, 1:max(clq_len)); Daniel@0: h=hist(clq_len, 1:max(clq_len)); Daniel@0: axis([1 max(clq_len)+1 0 max(h)+1]) Daniel@0: xlabel('clique size','fontsize',16) Daniel@0: ylabel('number','fontsize',16) Daniel@0: Daniel@0: Daniel@0: Daniel@0: