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_node.m @ 8:b5b38998ef3b

History | View | Annotate | Download (1.14 KB)

1
function [P, p] = prob_node(CPD, self_ev, pev)
2
% PROB_NODE Compute prod_m P(x(i,m)| x(pi_i,m), theta_i) for node i (discrete)
3
% [P, 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 (if there are any parents).
7
% (These may also be cell arrays.)
8
%
9
% p(m) = P(x(i,m)| x(pi_i,m), theta_i) 
10
% P = prod p(m)
11

    
12
if iscell(self_ev), usecell = 1; else usecell = 0; end
13

    
14
ncases = length(self_ev);
15
sz = dom_sizes(CPD);
16

    
17
nparents = length(sz)-1;
18
if nparents == 0
19
  assert(isempty(pev));
20
else
21
  assert(isequal(size(pev), [nparents ncases]));
22
end
23

    
24
n = length(sz);
25
dom = 1:n;
26
p = zeros(1, ncases);
27
if nparents == 0
28
  for m=1:ncases
29
    if usecell
30
      evidence = {self_ev{m}};
31
    else
32
      evidence = num2cell(self_ev(m));
33
    end
34
    T = convert_to_table(CPD, dom, evidence);
35
    p(m) = T;
36
  end
37
else
38
  for m=1:ncases
39
    if usecell
40
      evidence = cell(1,n);
41
      evidence(1:n-1) = pev(:,m);
42
      evidence(n) = self_ev(m);
43
    else
44
      evidence = num2cell([pev(:,m)', self_ev(m)]);
45
    end
46
    T = convert_to_table(CPD, dom, evidence);
47
    p(m) = T;
48
  end
49
end
50
P = prod(p);
51