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