annotate toolboxes/FullBNT-1.0.7/bnt/CPDs/@hhmmF_CPD/update_ess.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function CPD = update_ess(CPD, fmarginal, evidence, ns, cnodes, hidden_bitv)
Daniel@0 2 % UPDATE_ESS Update the Expected Sufficient Statistics of a hhmmF node.
Daniel@0 3 % function CPD = update_ess(CPD, fmarginal, evidence, ns, cnodes, hidden_bitv)
Daniel@0 4 %
Daniel@0 5 % We assume the F nodes are always hidden
Daniel@0 6
Daniel@0 7 % Figure out the node numbers associated with each parent
Daniel@0 8 dom = fmarginal.domain;
Daniel@0 9 %Fself = dom(end);
Daniel@0 10 %Fbelow = dom(CPD.Fbelow_ndx);
Daniel@0 11 Qself = dom(CPD.Qself_ndx);
Daniel@0 12 Qps = dom(CPD.Qps_ndx);
Daniel@0 13
Daniel@0 14 Qsz = CPD.Qsz;
Daniel@0 15 Qpsz = CPD.Qpsz;
Daniel@0 16
Daniel@0 17 if all(hidden_bitv(Qps)) % we assume all are hidden or all are observed
Daniel@0 18 k_ndx = 1:Qpsz;
Daniel@0 19 eff_Qpsz = Qpsz;
Daniel@0 20 else
Daniel@0 21 k_ndx = subv2ind(Qpsz, cat(1, evidence{Qps}));
Daniel@0 22 eff_Qpsz = 1;
Daniel@0 23 end
Daniel@0 24
Daniel@0 25 if hidden_bitv(Qself)
Daniel@0 26 j_ndx = 1:Qsz;
Daniel@0 27 eff_Qsz = Qsz;
Daniel@0 28 else
Daniel@0 29 j_ndx = evidence{Qself};
Daniel@0 30 eff_Qsz = 1;
Daniel@0 31 end
Daniel@0 32
Daniel@0 33 % Fmarginal(Qps, Q, Fbelow, F)
Daniel@0 34 fmarg = myreshape(fmarginal.T, [eff_Qpsz eff_Qsz 2 2]);
Daniel@0 35
Daniel@0 36 counts = zeros(Qpsz, Qsz, 2);
Daniel@0 37 %counts(k_ndx, j_ndx, :) = sum(fmarginal.T(:, :, :, :), 3); % sum over Fbelow
Daniel@0 38 counts(k_ndx, j_ndx, :) = fmarg(:, :, 2, :); % Fbelow = 2
Daniel@0 39
Daniel@0 40 CPD.sub_CPD_term = update_ess_simple(CPD.sub_CPD_term, counts);