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 / general / score_bnet_complete.m @ 8:b5b38998ef3b

History | View | Annotate | Download (945 Bytes)

1
function L = log_lik_complete(bnet, cases, clamped)
2
% LOG_LIK_COMPLETE Compute sum_m sum_i log P(x(i,m)| x(pi_i,m), theta_i) for a completely observed data set
3
% L = log_lik_complete(bnet, cases, clamped)
4
%
5
% If there is a missing data, you must use an inference engine.
6
% cases(i,m) is the value assigned to node i in case m.
7
% (If there are vector-valued nodes, cases should be a cell array.)
8
% clamped(i,m) = 1 if node i was set by intervention in case m (default: clamped = zeros)
9
% Clamped nodes contribute a factor of 1.0 to the likelihood.
10

    
11
if iscell(cases), usecell = 1; else usecell = 0; end
12

    
13
n = length(bnet.dag);
14
ncases = size(cases, 2);
15
if n ~= size(cases, 1)
16
  error('data should be of size nnodes * ncases');
17
end
18

    
19
if nargin < 3, clamped = zeros(n,ncases); end
20

    
21
L = 0;
22
for i=1:n
23
  ps = parents(bnet.dag, i);
24
  e = bnet.equiv_class(i);
25
  u = find(clamped(i,:)==0);
26
  L = L + log_prob_node(bnet.CPD{e}, cases(i,u), cases(ps,u));
27
end
28