wolffd@0
|
1 function marginal = marginal_difclq_nodes(engine, query_nodes)
|
wolffd@0
|
2 % MARGINAL_DIFCLQ_NODES get the marginal distribution of nodes which is not in a single clique
|
wolffd@0
|
3 % marginal = marginal_difclq_nodes(engine, query_nodes)
|
wolffd@0
|
4
|
wolffd@0
|
5 keyboard
|
wolffd@0
|
6 num_clique = length(engine.cliques);
|
wolffd@0
|
7 B = engine.cliques_bitv;
|
wolffd@0
|
8 clqs_containnodes = [];
|
wolffd@0
|
9 for i=1:length(query_nodes)
|
wolffd@0
|
10 node = query_nodes(i);
|
wolffd@0
|
11 tnodes = find(all(B(:, node), 2));
|
wolffd@0
|
12 clqs_containnodes = myunion(clqs_containnodes, tnodes);
|
wolffd@0
|
13 end
|
wolffd@0
|
14 % get all cliques contains query nodes
|
wolffd@0
|
15
|
wolffd@0
|
16 % get the minimal sub tree in junction which contains these cliques and the node closest to the root of jtree
|
wolffd@0
|
17 [subtree, nroot_node] = min_subtree_conti_nodes(engine.jtree, engine.root, clqs_containnodes);
|
wolffd@0
|
18 if ~mysubset(query_nodes, engine.cliques{nroot_node});
|
wolffd@0
|
19 % if query nodes is not all memers of the clique closest to the root clique performe push operation
|
wolffd@0
|
20 engine = push_tree(engine, subtree, query_nodes, nroot_node);
|
wolffd@0
|
21 end
|
wolffd@0
|
22
|
wolffd@0
|
23 if ~(nroot_node == engine.root)
|
wolffd@0
|
24 % if the clique closest to the root clique is not the root clique we must direct combine the
|
wolffd@0
|
25 % potential with the potential stored in separator toward to root
|
wolffd@0
|
26 p = parents(engine.jtree, nroot_node);
|
wolffd@0
|
27 tpot = direct_combine_pots(engine.clpot{nroot_node}, engine.seppot{p, nroot_node});
|
wolffd@0
|
28 else
|
wolffd@0
|
29 tpot = engine.clpot{nroot_node};
|
wolffd@0
|
30 end
|
wolffd@0
|
31
|
wolffd@0
|
32 pot = marginalize_pot(tpot, query_nodes);
|
wolffd@0
|
33 marginal = pot_to_marginal(pot);
|
wolffd@0
|
34 marginal.T = normalise(marginal.T);
|
wolffd@0
|
35
|
wolffd@0
|
36
|
wolffd@0
|
37
|
wolffd@0
|
38 function engine = push_tree(engine, tree, query_nodes, inode)
|
wolffd@0
|
39 % PUSH_TREE recursive perform push opeartion on tree
|
wolffd@0
|
40 % engine = push_tree(engine, tree, query_nodes, inode)
|
wolffd@0
|
41
|
wolffd@0
|
42 cs = children(tree, inode);
|
wolffd@0
|
43 for i = 1:length(cs)
|
wolffd@0
|
44 node = cs(i);
|
wolffd@0
|
45 push_tree(engine, tree, query_nodes, node);
|
wolffd@0
|
46 push_dom = myintersect(engine.cliques{node}, query_nodes);
|
wolffd@0
|
47 [engine, clqtoroot] = push(engine, node, push_dom);
|
wolffd@0
|
48 end
|
wolffd@0
|
49
|
wolffd@0
|
50
|
wolffd@0
|
51
|
wolffd@0
|
52
|
wolffd@0
|
53
|
wolffd@0
|
54
|
wolffd@0
|
55
|