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