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 / Old / prob_node.m @ 8:b5b38998ef3b
History | View | Annotate | Download (984 Bytes)
| 1 |
function p = prob_node(CPD, self_ev, pev) |
|---|---|
| 2 |
% PROB_NODE Compute P(y|pa(y), theta) (tabular) |
| 3 |
% p = prob_node(CPD, self_ev, pev) |
| 4 |
% |
| 5 |
% self_ev{m} is the evidence on this node in case m
|
| 6 |
% pev{i,m} is the evidence on the i'th parent in case m
|
| 7 |
% If there is a single case, self_ev can be a scalar instead of a cell array |
| 8 |
|
| 9 |
ncases = size(pev, 2); |
| 10 |
|
| 11 |
%assert(~any(isemptycell(pev))); % slow |
| 12 |
%assert(~any(isemptycell(self_ev))); % slow |
| 13 |
|
| 14 |
CPT = CPD_to_CPT(CPD); |
| 15 |
sz = mysize(CPT); |
| 16 |
nparents = length(sz)-1; |
| 17 |
assert(nparents == size(pev, 1)); |
| 18 |
|
| 19 |
if ncases==1 |
| 20 |
x = cat(1, pev{:});
|
| 21 |
if iscell(y) |
| 22 |
y = self_ev{1};
|
| 23 |
else |
| 24 |
y = self_ev; |
| 25 |
end |
| 26 |
switch nparents |
| 27 |
case 0, p = CPT(y); |
| 28 |
case 1, p = CPT(x(1), y); |
| 29 |
case 2, p = CPT(x(1), x(2), y); |
| 30 |
case 3, p = CPT(x(1), x(2), x(3), y); |
| 31 |
otherwise, |
| 32 |
ind = subv2ind(CPD.sizes, [x y]); |
| 33 |
p = CPT(ind); |
| 34 |
end |
| 35 |
else |
| 36 |
x = num2cell(pev)'; % each row is a case |
| 37 |
y = cat(1, self_ev{:})';
|
| 38 |
ind = subv2ind(CPD.sizes, [x y]); |
| 39 |
p = CPT(ind); |
| 40 |
end |