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