wolffd@0
|
1 function [pot, MEU] = marginal_nodes(engine, d)
|
wolffd@0
|
2
|
wolffd@0
|
3 C = length(cliques);
|
wolffd@0
|
4 %clpot = init_clpot(limid, cliques, d, clq_ass_to_node);
|
wolffd@0
|
5 clpot = init_clpot(limid, cliques, [], clq_ass_to_node);
|
wolffd@0
|
6
|
wolffd@0
|
7 % collect to root
|
wolffd@0
|
8 if 1
|
wolffd@0
|
9 % HUGIN
|
wolffd@0
|
10 seppot = cell(C, C); % separators are implicitely initialized to 1s
|
wolffd@0
|
11 for n=postorder{di}(1:end-1)
|
wolffd@0
|
12 for p=parents(rooted_jtree{di}, n)
|
wolffd@0
|
13 %clpot{p} = divide_by_pot(clpot{n}, seppot{p,n}); % dividing by 1 is redundant
|
wolffd@0
|
14 seppot{p,n} = marginalize_pot(clpot{n}, separator{p,n});
|
wolffd@0
|
15 clpot{p} = multiply_by_pot(clpot{p}, seppot{p,n});
|
wolffd@0
|
16 end
|
wolffd@0
|
17 end
|
wolffd@0
|
18 else
|
wolffd@0
|
19 % Shafer-Shenoy
|
wolffd@0
|
20 msg = cell(C,C);
|
wolffd@0
|
21 for n=postorder{di}(1:end-1)
|
wolffd@0
|
22 for c=children(rooted_jtree{di}, n)
|
wolffd@0
|
23 clpot{n} = multiply_by_pot(clpot{n}, msg{c,n});
|
wolffd@0
|
24 end
|
wolffd@0
|
25 p = parents(rooted_jtree{di}, n);
|
wolffd@0
|
26 %msg{n,p} = marginalize_pot(clpot{n}, cliques{p});
|
wolffd@0
|
27 msg{n,p} = marginalize_pot(clpot{n}, separator{n,p});
|
wolffd@0
|
28 end
|
wolffd@0
|
29 root = clq_ass_to_node(d);
|
wolffd@0
|
30 n=postorder{di}(end);
|
wolffd@0
|
31 assert(n == root);
|
wolffd@0
|
32 for c=children(rooted_jtree{di}, n)
|
wolffd@0
|
33 clpot{n} = multiply_by_pot(clpot{n}, msg{c,n});
|
wolffd@0
|
34 end
|
wolffd@0
|
35 end
|
wolffd@0
|
36
|
wolffd@0
|
37 fam = family(limid.dag, d);
|
wolffd@0
|
38 pot = marginalize_pot(clpot{root}, fam);
|
wolffd@0
|
39
|
wolffd@0
|
40 %%%%%%%
|
wolffd@0
|
41 jpot = compute_joint_pot_limid(limid);
|
wolffd@0
|
42 pot2 = marginalize_pot(jpot, fam);
|
wolffd@0
|
43 assert(approxeq_pot(pot, pot2))
|
wolffd@0
|
44 %%%%%%
|
wolffd@0
|
45
|
wolffd@0
|
46 [policy, score] = extract_policy(pot);
|
wolffd@0
|
47
|
wolffd@0
|
48 e = limid.equiv_class(d);
|
wolffd@0
|
49 limid.CPD{e} = set_params(limid.CPD{e}, 'policy', policy);
|
wolffd@0
|
50
|
wolffd@0
|
51
|
wolffd@0
|
52
|