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