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