Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/inference/static/@jtree_limid_inf_engine/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 | |
6 | |
7 bnet = bnet_from_engine(engine); | |
8 d = query; | |
9 assert(myismember(d, bnet.decision_nodes)); | |
10 fam = family(bnet.dag, d); | |
11 | |
12 clpot = init_clpot(bnet, engine.cliques, engine.clq_ass_to_node, engine.evidence, engine.exclude); | |
13 | |
14 % collect to root (clique containing d) | |
15 C = length(engine.cliques); | |
16 seppot = cell(C, C); % separators are implicitely initialized to 1s | |
17 for n=engine.postorder{d}(1:end-1) | |
18 for p=parents(engine.rooted_jtree{d}, n) | |
19 %clpot{p} = divide_by_pot(clpot{n}, seppot{p,n}); % dividing by 1 is redundant | |
20 seppot{p,n} = marginalize_pot(clpot{n}, engine.separator{p,n}); | |
21 clpot{p} = multiply_by_pot(clpot{p}, seppot{p,n}); | |
22 end | |
23 end | |
24 | |
25 root = engine.clq_ass_to_node(d); | |
26 assert(root == engine.postorder{d}(end)); | |
27 pot = marginalize_pot(clpot{root}, fam); | |
28 m = pot_to_marginal(pot); | |
29 | |
30 %%%%%%%%%%% | |
31 | |
32 | |
33 function clpot = init_clpot(bnet, cliques, clq_ass_to_node, evidence, exclude) | |
34 | |
35 % Set the clique potentials to all 1s | |
36 C = length(cliques); | |
37 clpot = cell(1, C); | |
38 ns = bnet.node_sizes; | |
39 for i=1:C | |
40 clpot{i} = upot(cliques{i}, ns(cliques{i})); | |
41 end | |
42 | |
43 N = length(bnet.dag); | |
44 nodes = mysetdiff(1:N, exclude); | |
45 | |
46 for n=nodes(:)' | |
47 fam = family(bnet.dag, n); | |
48 e = bnet.equiv_class(n); | |
49 c = clq_ass_to_node(n); | |
50 pot = convert_to_pot(bnet.CPD{e}, 'u', fam(:), evidence); | |
51 clpot{c} = multiply_by_pot(clpot{c}, pot); | |
52 end |