wolffd@0: function CPD = update_ess(CPD, fmarginal, evidence, ns, cnodes, hidden_bitv) wolffd@0: wolffd@0: marg = add_ev_to_dmarginal(fmarginal, evidence, ns); wolffd@0: wolffd@0: nps = length(CPD.dom_sz)-1; % num parents wolffd@0: wolffd@0: if ~isempty(CPD.Fbelow_ndx) wolffd@0: if ~isempty(CPD.Fself_ndx) % general case wolffd@0: ndx = mk_multi_index(nps+1, [CPD.Fbelow_ndx CPD.Fself_ndx], [2 1]); wolffd@0: CPD.trans_counts = CPD.trans_counts + squeeze(marg.T(ndx{:})); wolffd@0: ndx = mk_multi_index(nps+1, [CPD.Fbelow_ndx CPD.Fself_ndx], [2 2]); wolffd@0: CPD.start_counts = CPD.start_counts + squeeze(marg.T(ndx{:})); wolffd@0: else % no F from self, hence no startprob (top level) wolffd@0: ndx = mk_multi_index(nps+1, CPD.Fbelow_ndx, 2); wolffd@0: CPD.trans_counts = CPD.trans_counts + squeeze(marg.T(ndx{:})); wolffd@0: end wolffd@0: else % no F signal from below wolffd@0: if ~isempty(CPD.Fself_ndx) % self F (bottom level) wolffd@0: ndx = mk_multi_index(nps+1, CPD.Fself_ndx, 1); wolffd@0: CPD.trans_counts = CPD.trans_counts + squeeze(marg.T(ndx{:})); wolffd@0: ndx = mk_multi_index(nps+1, CPD.Fself_ndx, 2); wolffd@0: CPD.start_counts = CPD.start_counts + squeeze(marg.T(ndx{:})); wolffd@0: else % no F from self or below wolffd@0: error('no F signal') wolffd@0: end wolffd@0: end