Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/inference/dynamic/@ff_inf_engine/smooth_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, fwd, back, loglik] = smooth_evidence(engine, CPDpot, observed, pot_type) | |
2 % [marginals, fwd, back, loglik] = smooth_evidence(engine, CPDpot, observed, pot_type) (ff) | |
3 | |
4 error('ff smoothing is broken'); | |
5 | |
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 H = length(hnodes); | |
17 local_logscale = zeros(1,ss); | |
18 | |
19 t = 1; | |
20 for i=hnodes | |
21 fwd{i,t} = CPDpot{i,t}; | |
22 c = engine.obschild(i); | |
23 if 0 % c > 0 | |
24 fwd{i,t} = multiply_by_pot(fwd{i,t}, CPDpot{c, t}); | |
25 end | |
26 [fwd{i,t}, local_logscale(i)] = normalize_pot(fwd{i,t}); | |
27 end | |
28 logscale(t) = sum(local_logscale); | |
29 | |
30 for t=2:T | |
31 for i=hnodes | |
32 ps = parents(bnet.dag, i+ss); | |
33 assert(all(ps<=ss)); % in previous slice | |
34 prior = CPDpot{i,t}; | |
35 for p=ps(:)' | |
36 prior = multiply_by_pot(prior, fwd{p,t-1}); | |
37 end | |
38 fwd{i,t} = marginalize_pot(prior, i+ss); | |
39 fwd{i,t} = set_domain_pot(fwd{i,t}, i); | |
40 c = engine.obschild(i); | |
41 if 0 % c > 0 | |
42 fwd{i,t} = multiply_by_pot(fwd{i,t}, CPDpot{c,t}); | |
43 end | |
44 [fwd{i,t}, local_logscale(i)] = normalize_pot(fwd{i,t}); | |
45 end | |
46 logscale(t) = sum(local_logscale); | |
47 end | |
48 | |
49 loglik = sum(logscale); | |
50 | |
51 back = cell(ss,T); | |
52 t = T; | |
53 for i=hnodes | |
54 pot = dpot(i, ns(i)); | |
55 cs = children(bnet.intra, i); | |
56 for c=cs(:)' | |
57 pot = multiply_pots(pot, CPDpot{c,t}); | |
58 end | |
59 back{i,t} = marginalize_pot(pot, i); | |
60 back{i,t} = normalize_pot(back{i,t}); | |
61 back{i,t} = set_domain_pot(back{i,t}, i+ss); | |
62 end | |
63 for t=T-1:-1:1 | |
64 for i=hnodes | |
65 pot = dpot(i, ns(i)); | |
66 cs = children(bnet.inter, i); | |
67 for c=cs(:)' | |
68 pot = multiply_pots(pot, back{c,t+1}); | |
69 pot = multiply_pots(pot, CPDpot{c,t+1}); | |
70 end | |
71 cs = children(bnet.intra, i); | |
72 for c=cs(:)' | |
73 pot = multiply_pots(pot, CPDpot{c,t}); | |
74 end | |
75 back{i,t} = marginalize_pot(pot, i); | |
76 back{i,t} = normalize_pot(back{i,t}); | |
77 back{i,t} = set_domain_pot(back{i,t}, i+ss); | |
78 end | |
79 end | |
80 | |
81 | |
82 % COMBINE | |
83 for t=1:T | |
84 for i=hnodes | |
85 back{i,t} = set_domain_pot(back{i,t}, i); | |
86 fwd{i,t} = multiply_by_pot(fwd{i,t}, back{i,t}); | |
87 marginals{i,t} = normalize_pot(fwd{i,t}); | |
88 end | |
89 end |