comparison toolboxes/FullBNT-1.0.7/bnt/inference/static/@jtree_limid_inf_engine/jtree_limid_inf_engine.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 function engine = jtree_limid_inf_engine(bnet)
2 % JTREE_LIMID_INF_ENGINE Make a junction tree engine for use by solve_limid
3 % engine = jtree_limid_inf_engine(bnet)
4 %
5 % This engine is designed to compute marginals on decision nodes
6
7
8 MG = moralize(bnet.dag);
9 % We do not remove the utility nodes, because that complicates the book-keeping.
10 % Leaving them in will not introduce any un-necessary triangulation arcs, because they are always leaves.
11 % Also, since utility nodes have size 1, they do not increase the size of the potentials.
12
13 ns = bnet.node_sizes;
14 elim_order = best_first_elim_order(MG, ns);
15 [MTG, engine.cliques] = triangulate(MG, elim_order);
16 [engine.jtree, root, B, w] = cliques_to_jtree(engine.cliques, ns);
17
18 % A node can be a member of many cliques, but is assigned to exactly one, to avoid
19 % double-counting its CPD. We assign node i to clique c if c is the "lightest" clique that
20 % contains i's family, so it can accomodate its CPD.
21 N = length(bnet.dag);
22 engine.clq_ass_to_node = zeros(1, N);
23 for i=1:N
24 clqs_containing_family = find(all(B(:,family(bnet.dag, i)), 2)); % all selected columns must be 1
25 c = clqs_containing_family(argmin(w(clqs_containing_family)));
26 engine.clq_ass_to_node(i) = c;
27 end
28
29
30 % Compute the separators between connected cliques.
31 [is,js] = find(engine.jtree > 0);
32 num_cliques = length(engine.cliques);
33 engine.separator = cell(num_cliques, num_cliques);
34 for k=1:length(is)
35 i = is(k); j = js(k);
36 engine.separator{i,j} = find(B(i,:) & B(j,:)); % intersect(cliques{i}, cliques{j});
37 end
38
39
40 % create |D| different rooted jtree's
41 engine.rooted_jtree = cell(1, N);
42 engine.preorder = cell(1, N);
43 engine.postorder = cell(1, N);
44 for d=bnet.decision_nodes(:)'
45 root = engine.clq_ass_to_node(d);
46 [engine.rooted_jtree{d}, engine.preorder{d}, engine.postorder{d}] = mk_rooted_tree(engine.jtree, root);
47 end
48
49 engine.exclude = [];
50 engine.evidence = [];
51
52 engine = class(engine, 'jtree_limid_inf_engine', inf_engine(bnet));