Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/inference/dynamic/@ff_inf_engine/Old/enter_soft_evidence.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 [marginals, loglik] = enter_soft_evidence(engine, CPDpot, observed, pot_type, filter) | |
2 % ENTER_SOFT_EVIDENCE Add the specified soft evidence to the network (bk_ff) | |
3 % [marginals, loglik] = enter_soft_evidence(engine, CPDpot, observed, pot_type, filter) | |
4 | |
5 assert(pot_type == 'd'); | |
6 [ss T] = size(CPDpot); | |
7 fwd = cell(ss,T); | |
8 hnodes = engine.hnodes(:)'; | |
9 onodes = engine.onodes(:)'; | |
10 bnet = bnet_from_engine(engine); | |
11 ns = bnet.node_sizes; | |
12 onodes2 = [onodes onodes+ss]; | |
13 ns(onodes2) = 1; | |
14 | |
15 logscale = zeros(1,T); | |
16 local_logscale = zeros(1,length(hnodes)); | |
17 | |
18 t = 1; | |
19 for i=hnodes | |
20 fwd{i,t} = CPDpot{i,t}; | |
21 end | |
22 for i=onodes | |
23 p = parents(bnet.dag, i); | |
24 assert(length(p)==1); | |
25 ev = marginalize_pot(CPDpot{i,t}, p); | |
26 fwd{p,t} = multiply_by_pot(fwd{p,t}, ev); | |
27 end | |
28 for i=hnodes | |
29 [fwd{i,t}, local_logscale(i)] = normalize_pot(fwd{i,t}); | |
30 end | |
31 logscale(t) = sum(local_logscale); | |
32 | |
33 for t=2:T | |
34 for i=hnodes | |
35 ps = parents(bnet.dag, i+ss); | |
36 assert(all(ps<=ss)); % in previous slice | |
37 prior = CPDpot{i,t}; | |
38 for p=ps(:)' | |
39 prior = multiply_by_pot(prior, fwd{p,t-1}); | |
40 end | |
41 fwd{i,t} = marginalize_pot(prior, i+ss); | |
42 fwd{i,t} = set_domain_pot(fwd{i,t}, i); | |
43 end | |
44 for i=onodes | |
45 p = parents(bnet.dag, i); | |
46 assert(length(p)==1); | |
47 temp = pot_to_marginal(CPDpot{i,t}); | |
48 ev = dpot(p, ns(p), temp.T); | |
49 fwd{p,t} = multiply_by_pot(fwd{p,t}, ev); | |
50 end | |
51 | |
52 for i=hnodes | |
53 [fwd{i,t}, local_logscale(i)] = normalize_pot(fwd{i,t}); | |
54 end | |
55 logscale(t) = sum(local_logscale); | |
56 end | |
57 | |
58 marginals = fwd; | |
59 loglik = sum(logscale); |