Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/inference/static/@jtree_limid_inf_engine/Old/marginal_family.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 [m, pot] = marginal_family(engine, query) | |
2 % MARGINAL_NODES Compute the marginal on the family of the specified node (jtree_limid) | |
3 % [m, pot] = marginal_family(engine, query) | |
4 % | |
5 % query should be a single decision node, or [] (to compute global max expected utility) | |
6 | |
7 bnet = bnet_from_engine(engine); | |
8 if isempty(query) | |
9 compute_meu = 1; | |
10 d = bnet.decision_nodes(1); % pick an arbitrary root to collect to | |
11 fam = []; % marginalize root pot down to a point | |
12 else | |
13 compute_meu = 0; | |
14 d = query; | |
15 assert(myismember(d, bnet.decision_nodes)); | |
16 fam = family(bnet.dag, d); | |
17 end | |
18 | |
19 clpot = init_clpot(bnet, engine.cliques, engine.clq_ass_to_node, engine.evidence, engine.exclude); | |
20 | |
21 % collect to root (clique containing d) | |
22 C = length(engine.cliques); | |
23 seppot = cell(C, C); % separators are implicitely initialized to 1s | |
24 for n=engine.postorder{d}(1:end-1) | |
25 for p=parents(engine.rooted_jtree{d}, n) | |
26 %clpot{p} = divide_by_pot(clpot{n}, seppot{p,n}); % dividing by 1 is redundant | |
27 seppot{p,n} = marginalize_pot(clpot{n}, engine.separator{p,n}); | |
28 clpot{p} = multiply_by_pot(clpot{p}, seppot{p,n}); | |
29 end | |
30 end | |
31 | |
32 root = engine.clq_ass_to_node(d); | |
33 assert(root == engine.postorder{d}(end)); | |
34 pot = marginalize_pot(clpot{root}, fam); | |
35 m = pot_to_marginal(pot); | |
36 | |
37 %%%%%%%%%%% | |
38 | |
39 | |
40 function clpot = init_clpot(bnet, cliques, clq_ass_to_node, evidence, exclude) | |
41 | |
42 % Set the clique potentials to all 1s | |
43 C = length(cliques); | |
44 clpot = cell(1, C); | |
45 ns = bnet.node_sizes; | |
46 for i=1:C | |
47 clpot{i} = upot(cliques{i}, ns(cliques{i})); | |
48 end | |
49 | |
50 N = length(bnet.dag); | |
51 nodes = mysetdiff(1:N, exclude); | |
52 | |
53 for n=nodes(:)' | |
54 fam = family(bnet.dag, n); | |
55 e = bnet.equiv_class(n); | |
56 c = clq_ass_to_node(n); | |
57 pot = convert_to_pot(bnet.CPD{e}, 'u', ns, fam, evidence); | |
58 clpot{c} = multiply_by_pot(clpot{c}, pot); | |
59 end |