comparison toolboxes/FullBNT-1.0.7/bnt/CPDs/@hhmmF_CPD/update_ess.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 CPD = update_ess(CPD, fmarginal, evidence, ns, cnodes, hidden_bitv)
2 % UPDATE_ESS Update the Expected Sufficient Statistics of a hhmmF node.
3 % function CPD = update_ess(CPD, fmarginal, evidence, ns, cnodes, hidden_bitv)
4 %
5 % We assume the F nodes are always hidden
6
7 % Figure out the node numbers associated with each parent
8 dom = fmarginal.domain;
9 %Fself = dom(end);
10 %Fbelow = dom(CPD.Fbelow_ndx);
11 Qself = dom(CPD.Qself_ndx);
12 Qps = dom(CPD.Qps_ndx);
13
14 Qsz = CPD.Qsz;
15 Qpsz = CPD.Qpsz;
16
17 if all(hidden_bitv(Qps)) % we assume all are hidden or all are observed
18 k_ndx = 1:Qpsz;
19 eff_Qpsz = Qpsz;
20 else
21 k_ndx = subv2ind(Qpsz, cat(1, evidence{Qps}));
22 eff_Qpsz = 1;
23 end
24
25 if hidden_bitv(Qself)
26 j_ndx = 1:Qsz;
27 eff_Qsz = Qsz;
28 else
29 j_ndx = evidence{Qself};
30 eff_Qsz = 1;
31 end
32
33 % Fmarginal(Qps, Q, Fbelow, F)
34 fmarg = myreshape(fmarginal.T, [eff_Qpsz eff_Qsz 2 2]);
35
36 counts = zeros(Qpsz, Qsz, 2);
37 %counts(k_ndx, j_ndx, :) = sum(fmarginal.T(:, :, :, :), 3); % sum over Fbelow
38 counts(k_ndx, j_ndx, :) = fmarg(:, :, 2, :); % Fbelow = 2
39
40 CPD.sub_CPD_term = update_ess_simple(CPD.sub_CPD_term, counts);