matthiasm@8: function L = log_nextcase_prob_node(CPD, self_ev, pev, test_self_ev, test_pev) matthiasm@8: % LOG_NEXTCASE_PROB_NODE compute the joint distribution of a node (tabular) of a new case given matthiasm@8: % completely observed data. matthiasm@8: % matthiasm@8: % The input arguments are mainly similar with log_marg_prob_node(CPD, self_ev, pev, usecell), matthiasm@8: % but add test_self_ev, test_pev, and without usecell matthiasm@8: % test_self_ev(m) is the evidence on this node in a test case. matthiasm@8: % test_pev(i) is the evidence on the i'th parent in the test case (if there are any parents). matthiasm@8: % matthiasm@8: % Written by qian.diao@intel.com matthiasm@8: matthiasm@8: ncases = length(self_ev); matthiasm@8: sz = CPD.sizes; matthiasm@8: nparents = length(sz)-1; matthiasm@8: assert(ncases == size(pev, 2)); matthiasm@8: matthiasm@8: if nargin < 6 matthiasm@8: %usecell = 0; matthiasm@8: if iscell(self_ev) matthiasm@8: usecell = 1; matthiasm@8: else matthiasm@8: usecell = 0; matthiasm@8: end matthiasm@8: end matthiasm@8: matthiasm@8: matthiasm@8: if ncases==0 matthiasm@8: L = 0; matthiasm@8: return; matthiasm@8: elseif ncases==1 % speedup the sequential learning case; here need correction!!! matthiasm@8: CPT = CPD.CPT; matthiasm@8: % We assume the CPTs are already set to the mean of the posterior (due to bayes_update_params) matthiasm@8: if usecell matthiasm@8: x = cat(1, pev{:})'; matthiasm@8: y = self_ev{1}; matthiasm@8: else matthiasm@8: %x = pev(:)'; matthiasm@8: x = pev; matthiasm@8: y = self_ev; matthiasm@8: end matthiasm@8: switch nparents matthiasm@8: case 0, p = CPT(y); matthiasm@8: case 1, p = CPT(x(1), y); matthiasm@8: case 2, p = CPT(x(1), x(2), y); matthiasm@8: case 3, p = CPT(x(1), x(2), x(3), y); matthiasm@8: otherwise, matthiasm@8: ind = subv2ind(sz, [x y]); matthiasm@8: p = CPT(ind); matthiasm@8: end matthiasm@8: L = log(p); matthiasm@8: else matthiasm@8: % We ignore the CPTs here and assume the prior has not been changed matthiasm@8: matthiasm@8: % We arrange the data as in the following example. matthiasm@8: % Let there be 2 parents and 3 cases. Let p(i,m) be parent i in case m, matthiasm@8: % and y(m) be the child in case m. Then we create the data matrix matthiasm@8: % matthiasm@8: % p(1,1) p(1,2) p(1,3) matthiasm@8: % p(2,1) p(2,2) p(2,3) matthiasm@8: % y(1) y(2) y(3) matthiasm@8: if usecell matthiasm@8: data = [cell2num(pev); cell2num(self_ev)]; matthiasm@8: else matthiasm@8: data = [pev; self_ev]; matthiasm@8: end matthiasm@8: counts = compute_counts(data, sz); matthiasm@8: matthiasm@8: % compute the (N_ijk'+ N_ijk)/(N_ij' + N_ij) under the condition of 1_m+1,ijk = 1 matthiasm@8: L = predict_family(counts, CPD.prior, test_self_ev, test_pev); matthiasm@8: end matthiasm@8: matthiasm@8: