Daniel@0: function CPD = update_ess(CPD, fmarginal, evidence, ns, cnodes, hidden_bitv) Daniel@0: % UPDATE_ESS Update the Expected Sufficient Statistics of a hhmmF node. Daniel@0: % function CPD = update_ess(CPD, fmarginal, evidence, ns, cnodes, hidden_bitv) Daniel@0: % Daniel@0: % We assume the F nodes are always hidden Daniel@0: Daniel@0: % Figure out the node numbers associated with each parent Daniel@0: dom = fmarginal.domain; Daniel@0: %Fself = dom(end); Daniel@0: %Fbelow = dom(CPD.Fbelow_ndx); Daniel@0: Qself = dom(CPD.Qself_ndx); Daniel@0: Qps = dom(CPD.Qps_ndx); Daniel@0: Daniel@0: Qsz = CPD.Qsz; Daniel@0: Qpsz = CPD.Qpsz; Daniel@0: Daniel@0: if all(hidden_bitv(Qps)) % we assume all are hidden or all are observed Daniel@0: k_ndx = 1:Qpsz; Daniel@0: eff_Qpsz = Qpsz; Daniel@0: else Daniel@0: k_ndx = subv2ind(Qpsz, cat(1, evidence{Qps})); Daniel@0: eff_Qpsz = 1; Daniel@0: end Daniel@0: Daniel@0: if hidden_bitv(Qself) Daniel@0: j_ndx = 1:Qsz; Daniel@0: eff_Qsz = Qsz; Daniel@0: else Daniel@0: j_ndx = evidence{Qself}; Daniel@0: eff_Qsz = 1; Daniel@0: end Daniel@0: Daniel@0: % Fmarginal(Qps, Q, Fbelow, F) Daniel@0: fmarg = myreshape(fmarginal.T, [eff_Qpsz eff_Qsz 2 2]); Daniel@0: Daniel@0: counts = zeros(Qpsz, Qsz, 2); Daniel@0: %counts(k_ndx, j_ndx, :) = sum(fmarginal.T(:, :, :, :), 3); % sum over Fbelow Daniel@0: counts(k_ndx, j_ndx, :) = fmarg(:, :, 2, :); % Fbelow = 2 Daniel@0: Daniel@0: CPD.sub_CPD_term = update_ess_simple(CPD.sub_CPD_term, counts);