wolffd@0
|
1 function [engine, loglik] = dbn_update_bel(engine, evidence)
|
wolffd@0
|
2 % DBN_UPDATE_BEL Update the belief state (bk)
|
wolffd@0
|
3 % [engine, loglik] = dbn_update_bel(engine, evidence)
|
wolffd@0
|
4 %
|
wolffd@0
|
5 % evidence{i,1} contains the evidence on node i in slice t-1
|
wolffd@0
|
6 % evidence{i,2} contains the evidence on node i in slice t
|
wolffd@0
|
7
|
wolffd@0
|
8 oldbel = engine.bel;
|
wolffd@0
|
9
|
wolffd@0
|
10 ss = size(evidence, 1);
|
wolffd@0
|
11 bnet = bnet_from_engine(engine);
|
wolffd@0
|
12 CPDpot = cell(1, ss);
|
wolffd@0
|
13 for n=1:ss
|
wolffd@0
|
14 fam = family(bnet.dag, n, 2);
|
wolffd@0
|
15 e = bnet.equiv_class(n, 2);
|
wolffd@0
|
16 CPDpot{n} = convert_to_pot(bnet.CPD{e}, engine.pot_type, fam(:), evidence);
|
wolffd@0
|
17 end
|
wolffd@0
|
18
|
wolffd@0
|
19 observed = ~isemptycell(evidence);
|
wolffd@0
|
20 onodes2 = find(observed(:));
|
wolffd@0
|
21 clqs = [engine.clq_ass_to_cluster(:,1); engine.clq_ass_to_node(:,2)];
|
wolffd@0
|
22 pots = [oldbel(:); CPDpot(:)];
|
wolffd@0
|
23
|
wolffd@0
|
24 [clpot, loglik] = enter_soft_evidence(engine.sub_engine, clqs, pots, onodes2(:), engine.pot_type);
|
wolffd@0
|
25
|
wolffd@0
|
26 C = length(engine.clusters);
|
wolffd@0
|
27 newbel = cell(1,C);
|
wolffd@0
|
28 for c=1:C
|
wolffd@0
|
29 k = engine.clq_ass_to_cluster(c,2);
|
wolffd@0
|
30 cl = engine.clusters{c};
|
wolffd@0
|
31 newbel{c} = marginalize_pot(clpot{k}, cl+ss); % extract slice 2 posterior
|
wolffd@0
|
32 newbel{c} = set_domain_pot(newbel{c}, cl); % shift back to slice 1 for re-use as prior
|
wolffd@0
|
33 end
|
wolffd@0
|
34
|
wolffd@0
|
35 engine.bel = newbel;
|
wolffd@0
|
36 engine.bel_clpot = clpot;
|
wolffd@0
|
37 engine.slice1 = 0;
|