wolffd@0
|
1 function CPDpot = convert_dbn_CPDs_to_tables_slow(bnet, evidence)
|
wolffd@0
|
2 % CONVERT_DBN_CPDS_TO_TABLES_SLOW Convert CPDs of (possibly instantiated) DBN nodes to tables
|
wolffd@0
|
3 % CPDpot = convert_dbn_CPDs_to_tables_slow(bnet, evidence)
|
wolffd@0
|
4 %
|
wolffd@0
|
5 % CPDpot{n,t} is a table containing P(n,t|pa(n,t), ev)
|
wolffd@0
|
6 % All hidden nodes are assumed to be discrete
|
wolffd@0
|
7 %
|
wolffd@0
|
8 % Non-vectorized method; this is less efficient for long sequences of observed Gaussian
|
wolffd@0
|
9 % nodes, because of the (unnecessary) repeated matrix inversion.
|
wolffd@0
|
10
|
wolffd@0
|
11 obs_bitv = ~isemptycell(evidence(:));
|
wolffd@0
|
12 [ss T] = size(evidence);
|
wolffd@0
|
13 ns = bnet.node_sizes(:);
|
wolffd@0
|
14
|
wolffd@0
|
15 CPDpot = cell(ss,T);
|
wolffd@0
|
16
|
wolffd@0
|
17 t = 1;
|
wolffd@0
|
18 for n=1:ss
|
wolffd@0
|
19 %ps = engine.bnet_parents{n};
|
wolffd@0
|
20 ps = parents(bnet.dag, n);
|
wolffd@0
|
21 e = bnet.equiv_class(n, 1);
|
wolffd@0
|
22 if ~any(obs_bitv(ps))
|
wolffd@0
|
23 CPDpot{n,t} = convert_CPD_to_table_hidden_ps(bnet.CPD{e}, evidence{n,t});
|
wolffd@0
|
24 else
|
wolffd@0
|
25 CPDpot{n,t} = convert_to_table(bnet.CPD{e}, [ps n], evidence(:,1));
|
wolffd@0
|
26 end
|
wolffd@0
|
27 end
|
wolffd@0
|
28 for t=2:T
|
wolffd@0
|
29 for n=1:ss
|
wolffd@0
|
30 self = n+ss;
|
wolffd@0
|
31 ps = parents(bnet.dag, self);
|
wolffd@0
|
32 e = bnet.equiv_class(n, 2);
|
wolffd@0
|
33 if ~any(obs_bitv(ps))
|
wolffd@0
|
34 CPDpot{n,t} = convert_CPD_to_table_hidden_ps(bnet.CPD{e}, evidence{n,t});
|
wolffd@0
|
35 else
|
wolffd@0
|
36 CPDpot{n,t} = convert_to_table(bnet.CPD{e}, [ps self], evidence(:,t-1:t));
|
wolffd@0
|
37 end
|
wolffd@0
|
38 end
|
wolffd@0
|
39 end
|
wolffd@0
|
40
|
wolffd@0
|
41
|