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 / @gaussian_CPD / log_prob_node.m @ 8:b5b38998ef3b
History | View | Annotate | Download (1.11 KB)
| 1 |
function L = log_prob_node(CPD, self_ev, pev) |
|---|---|
| 2 |
% LOG_PROB_NODE Compute prod_m log P(x(i,m)| x(pi_i,m), theta_i) for node i (gaussian) |
| 3 |
% L = log_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 (if there are any parents). |
| 7 |
% (These may also be cell arrays.) |
| 8 |
|
| 9 |
if iscell(self_ev), usecell = 1; else usecell = 0; end |
| 10 |
|
| 11 |
use_log = 1; |
| 12 |
ncases = length(self_ev); |
| 13 |
nparents = length(CPD.sizes)-1; |
| 14 |
assert(ncases == size(pev, 2)); |
| 15 |
|
| 16 |
if ncases == 0 |
| 17 |
L = 0; |
| 18 |
return; |
| 19 |
end |
| 20 |
|
| 21 |
L = 0; |
| 22 |
for m=1:ncases |
| 23 |
if isempty(CPD.dps) |
| 24 |
i = 1; |
| 25 |
else |
| 26 |
if usecell |
| 27 |
dpvals = cat(1, pev{CPD.dps, m});
|
| 28 |
else |
| 29 |
dpvals = pev(CPD.dps, m); |
| 30 |
end |
| 31 |
i = subv2ind(CPD.sizes(CPD.dps), dpvals(:)'); |
| 32 |
end |
| 33 |
if usecell |
| 34 |
y = self_ev{m};
|
| 35 |
else |
| 36 |
y = self_ev(m); |
| 37 |
end |
| 38 |
if length(CPD.cps) == 0 |
| 39 |
L = L + gaussian_prob(y, CPD.mean(:,i), CPD.cov(:,:,i), use_log); |
| 40 |
else |
| 41 |
if usecell |
| 42 |
x = cat(1, pev{CPD.cps, m});
|
| 43 |
else |
| 44 |
x = pev(CPD.cps, m); |
| 45 |
end |
| 46 |
L = L + gaussian_prob(y, CPD.mean(:,i) + CPD.weights(:,:,i)*x, CPD.cov(:,:,i), use_log); |
| 47 |
end |
| 48 |
end |
| 49 |
|