comparison toolboxes/FullBNT-1.0.7/bnt/inference/static/@stab_cond_gauss_inf_engine/Old/initialize_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, loglik] = initialize_engine(engine)
2 %initialize
3 bnet = bnet_from_engine(engine);
4 ns = bnet.node_sizes(:);
5 N = length(bnet.dag);
6
7 pot_type = 'scg'
8 check_for_cd_arcs([], bnet.cnodes, bnet.dag);
9
10 % Evaluate CPDs with evidence, and convert to potentials
11 pot = cell(1, N);
12 C = length(engine.cliques);
13 inited = zeros(1, C);
14 clpot = cell(1, C);
15 evidence = cell(1, N);
16 for n=1:N
17 fam = family(bnet.dag, n);
18 e = bnet.equiv_class(n);
19 pot{n} = CPD_to_scgpot(bnet.CPD{e}, fam, ns, bnet.cnodes, evidence);
20 cindex = engine.clq_ass_to_node(n);
21 if inited(cindex)
22 %clpot{cindex} = direct_combine_pots(clpot{cindex}, pot{n});
23 clpot{cindex} = direct_combine_pots(pot{n}, clpot{cindex});
24 else
25 clpot{cindex} = pot{n};
26 inited(cindex) = 1;
27 end
28 end
29
30 for i=1:C
31 if inited(i) == 0
32 clpot{i} = scgpot([], [], [], []);
33 end
34 end
35
36 seppot = cell(C, C);
37 % separators are is not need to initialize
38
39 % collect to root (node to parents)
40 for n=engine.postorder(1:end-1)
41 for p=parents(engine.jtree, n)
42 [margpot, comppot] = complement_pot(clpot{n}, engine.separator{p,n});
43 margpot = marginalize_pot(clpot{n}, engine.separator{p,n});
44 clpot{n} = comppot;
45 %seppot{p, n} = margpot;
46 clpot{p} = combine_pots(clpot{p}, margpot);
47 %clpot{p} = combine_pots(margpot, clpot{p});
48 end
49 end
50
51 temppot = clpot;
52 %temppot = clpot{engine.root};
53 for n=engine.preorder
54 for c=children(engine.jtree, n)
55 seppot{n,c} = marginalize_pot(temppot{n}, engine.separator{n,c});
56 %seppot{n,c} = marginalize_pot(clpot{n}, engine.separator{n,c});
57 %clpot{c} = direct_combine_pots(clpot{c}, seppot{n,c});
58 temppot{c} = direct_combine_pots(temppot{c}, seppot{n,c});
59 end
60 end
61
62 engine.clpot = clpot;
63 engine.seppot = seppot;
64
65