comparison toolboxes/FullBNT-1.0.7/bnt/examples/dynamic/Old/online1.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 % Check that online inference gives same results as filtering for various algorithms
2
3 N = 3;
4 Q = 2;
5 ss = N*2;
6
7 rand('state', 0);
8 randn('state', 0);
9
10
11 obs_size = 1;
12 discrete_obs = 0;
13 bnet = mk_chmm(N, Q, obs_size, discrete_obs);
14 ns = bnet.node_sizes_slice;
15
16 engine = {};
17 engine{end+1} = hmm_inf_engine(bnet);
18 E = length(engine);
19
20 onodes = (1:N)+N;
21
22 T = 4;
23 ev = cell(ss,T);
24 ev(onodes,:) = num2cell(randn(N, T));
25
26
27 filter = 1;
28 loglik2 = zeros(1,E);
29 for e=1:E
30 [engine2{e}, loglik2(e)] = enter_evidence(engine{e}, ev, 'filter', filter);
31 end
32
33 loglik = zeros(1,E);
34 marg1 = cell(E,N,T);
35 for e=1:E
36 ll = zeros(1,T);
37 engine{e} = dbn_init_bel(engine{e});
38 for t=1:T
39 [engine{e}, ll(t)] = dbn_update_bel(engine{e}, ev(:,t), t);
40 for i=1:N
41 marg1{e,i,t} = dbn_marginal_from_bel(engine{e}, i);
42 end
43 end
44 loglik1(e) = sum(ll);
45 end
46
47 assert(approxeq(loglik1, loglik2))
48
49 a = zeros(E,N,T);
50 for e=1:E
51 for t=1:T
52 for i=1:N
53 marg2{e,i,t} = marginal_nodes(engine2{e}, i, t);
54 a(e,i,t) = (approxeq(marg2{e,i,t}.T(:), marg1{e,i,t}.T(:)));
55 end
56 end
57 end
58
59 assert(all(a(:)==1))