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

History | View | Annotate | Download (1.23 KB)

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

    
14
if iscell(cases), usecell = 1; else usecell = 0; end
15

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

    
22
if ncases == 1
23
  if nargin < 3, clamped = []; end
24
  clamp_set = clamped;
25
  clamped = zeros(n,1);
26
  clamped(clamp_set) = 1;
27
else
28
  if nargin < 3, clamped = zeros(n,ncases); end
29
end
30

    
31
L = 0;
32
for i=1:n
33
  ps = parents(bnet.dag, i);
34
  e = bnet.equiv_class(i);
35
  u = find(clamped(i,:)==0);
36
  L = L + log_marg_prob_node(bnet.CPD{e}, cases(i,u), cases(ps,u));
37
end
38

    
39

    
40