annotate _FullBNT/BNT/CPDs/@tabular_CPD/log_nextcase_prob_node.m @ 9:4ea6619cb3f5 tip

removed log files
author matthiasm
date Fri, 11 Apr 2014 15:55:11 +0100
parents b5b38998ef3b
children
rev   line source
matthiasm@8 1 function L = log_nextcase_prob_node(CPD, self_ev, pev, test_self_ev, test_pev)
matthiasm@8 2 % LOG_NEXTCASE_PROB_NODE compute the joint distribution of a node (tabular) of a new case given
matthiasm@8 3 % completely observed data.
matthiasm@8 4 %
matthiasm@8 5 % The input arguments are mainly similar with log_marg_prob_node(CPD, self_ev, pev, usecell),
matthiasm@8 6 % but add test_self_ev, test_pev, and without usecell
matthiasm@8 7 % test_self_ev(m) is the evidence on this node in a test case.
matthiasm@8 8 % test_pev(i) is the evidence on the i'th parent in the test case (if there are any parents).
matthiasm@8 9 %
matthiasm@8 10 % Written by qian.diao@intel.com
matthiasm@8 11
matthiasm@8 12 ncases = length(self_ev);
matthiasm@8 13 sz = CPD.sizes;
matthiasm@8 14 nparents = length(sz)-1;
matthiasm@8 15 assert(ncases == size(pev, 2));
matthiasm@8 16
matthiasm@8 17 if nargin < 6
matthiasm@8 18 %usecell = 0;
matthiasm@8 19 if iscell(self_ev)
matthiasm@8 20 usecell = 1;
matthiasm@8 21 else
matthiasm@8 22 usecell = 0;
matthiasm@8 23 end
matthiasm@8 24 end
matthiasm@8 25
matthiasm@8 26
matthiasm@8 27 if ncases==0
matthiasm@8 28 L = 0;
matthiasm@8 29 return;
matthiasm@8 30 elseif ncases==1 % speedup the sequential learning case; here need correction!!!
matthiasm@8 31 CPT = CPD.CPT;
matthiasm@8 32 % We assume the CPTs are already set to the mean of the posterior (due to bayes_update_params)
matthiasm@8 33 if usecell
matthiasm@8 34 x = cat(1, pev{:})';
matthiasm@8 35 y = self_ev{1};
matthiasm@8 36 else
matthiasm@8 37 %x = pev(:)';
matthiasm@8 38 x = pev;
matthiasm@8 39 y = self_ev;
matthiasm@8 40 end
matthiasm@8 41 switch nparents
matthiasm@8 42 case 0, p = CPT(y);
matthiasm@8 43 case 1, p = CPT(x(1), y);
matthiasm@8 44 case 2, p = CPT(x(1), x(2), y);
matthiasm@8 45 case 3, p = CPT(x(1), x(2), x(3), y);
matthiasm@8 46 otherwise,
matthiasm@8 47 ind = subv2ind(sz, [x y]);
matthiasm@8 48 p = CPT(ind);
matthiasm@8 49 end
matthiasm@8 50 L = log(p);
matthiasm@8 51 else
matthiasm@8 52 % We ignore the CPTs here and assume the prior has not been changed
matthiasm@8 53
matthiasm@8 54 % We arrange the data as in the following example.
matthiasm@8 55 % Let there be 2 parents and 3 cases. Let p(i,m) be parent i in case m,
matthiasm@8 56 % and y(m) be the child in case m. Then we create the data matrix
matthiasm@8 57 %
matthiasm@8 58 % p(1,1) p(1,2) p(1,3)
matthiasm@8 59 % p(2,1) p(2,2) p(2,3)
matthiasm@8 60 % y(1) y(2) y(3)
matthiasm@8 61 if usecell
matthiasm@8 62 data = [cell2num(pev); cell2num(self_ev)];
matthiasm@8 63 else
matthiasm@8 64 data = [pev; self_ev];
matthiasm@8 65 end
matthiasm@8 66 counts = compute_counts(data, sz);
matthiasm@8 67
matthiasm@8 68 % compute the (N_ijk'+ N_ijk)/(N_ij' + N_ij) under the condition of 1_m+1,ijk = 1
matthiasm@8 69 L = predict_family(counts, CPD.prior, test_self_ev, test_pev);
matthiasm@8 70 end
matthiasm@8 71
matthiasm@8 72