Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/inference/dynamic/@ff_inf_engine/filter_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 [fwd, loglik] = filter_evidence(engine, CPDpot, observed, pot_type) | |
2 % [fwd, loglik] = filter_evidence(engine, CPDpot, observed, pot_type) (ff) | |
3 | |
4 [ss T] = size(CPDpot); | |
5 fwd = cell(ss,T); | |
6 hnodes = engine.hnodes(:)'; | |
7 onodes = engine.onodes(:)'; | |
8 bnet = bnet_from_engine(engine); | |
9 ns = bnet.node_sizes; | |
10 onodes2 = [onodes onodes+ss]; | |
11 ns(onodes2) = 1; | |
12 | |
13 logscale = zeros(1,T); | |
14 H = length(hnodes); | |
15 local_logscale = zeros(1,ss); | |
16 | |
17 t = 1; | |
18 for i=hnodes | |
19 fwd{i,t} = CPDpot{i,t}; | |
20 c = engine.obschild(i); | |
21 if c > 0 | |
22 fwd{i,t} = multiply_by_pot(fwd{i,t}, CPDpot{c, t}); | |
23 end | |
24 [fwd{i,t}, local_logscale(i)] = normalize_pot(fwd{i,t}); | |
25 end | |
26 logscale(t) = sum(local_logscale); | |
27 | |
28 for t=2:T | |
29 for i=hnodes | |
30 ps = parents(bnet.dag, i+ss); | |
31 assert(all(ps<=ss)); % in previous slice | |
32 prior = CPDpot{i,t}; | |
33 for p=ps(:)' | |
34 prior = multiply_by_pot(prior, fwd{p,t-1}); | |
35 end | |
36 fwd{i,t} = marginalize_pot(prior, i+ss); | |
37 fwd{i,t} = set_domain_pot(fwd{i,t}, i); | |
38 c = engine.obschild(i); | |
39 if c > 0 | |
40 fwd{i,t} = multiply_by_pot(fwd{i,t}, CPDpot{c,t}); | |
41 end | |
42 [fwd{i,t}, local_logscale(i)] = normalize_pot(fwd{i,t}); | |
43 end | |
44 logscale(t) = sum(local_logscale); | |
45 end | |
46 | |
47 loglik = sum(logscale); | |
48 |