To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Revision:

root / _FullBNT / BNT / CPDs / @discrete_CPD / Old / prob_CPD.m @ 8:b5b38998ef3b

History | View | Annotate | Download (628 Bytes)

1
function p = prob_CPD(CPD, domain, ns, cnodes, evidence)
2
% PROB_CPD Compute prob of a node given evidence on the parents (discrete)
3
% p = prob_CPD(CPD, domain, ns, cnodes, evidence)
4
%
5
% domain is the domain of CPD.
6
% node_sizes(i) is the size of node i.
7
% cnodes = all the cts nodes
8
% evidence{i} is the evidence on the i'th node.
9

    
10
ps = domain(1:end-1);
11
self = domain(end);
12
CPT = CPD_to_CPT(CPD);
13

    
14
if isempty(ps)
15
  T = CPT;
16
else
17
  assert(~any(isemptycell(evidence(ps))));
18
  pvals = cat(1, evidence{ps});
19
  i = subv2ind(ns(ps), pvals(:)');
20
  T = reshape(CPT, [prod(ns(ps)) ns(self)]);
21
  T = T(i,:);
22
end
23
p = T(evidence{self});
24

    
25