wolffd@0
|
1 function L = log_lik_complete(bnet, cases, clamped)
|
wolffd@0
|
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
|
wolffd@0
|
3 % L = log_lik_complete(bnet, cases, clamped)
|
wolffd@0
|
4 %
|
wolffd@0
|
5 % If there is a missing data, you must use an inference engine.
|
wolffd@0
|
6 % cases(i,m) is the value assigned to node i in case m.
|
wolffd@0
|
7 % (If there are vector-valued nodes, cases should be a cell array.)
|
wolffd@0
|
8 % clamped(i,m) = 1 if node i was set by intervention in case m (default: clamped = zeros)
|
wolffd@0
|
9 % Clamped nodes contribute a factor of 1.0 to the likelihood.
|
wolffd@0
|
10
|
wolffd@0
|
11 if iscell(cases), usecell = 1; else usecell = 0; end
|
wolffd@0
|
12
|
wolffd@0
|
13 n = length(bnet.dag);
|
wolffd@0
|
14 ncases = size(cases, 2);
|
wolffd@0
|
15 if n ~= size(cases, 1)
|
wolffd@0
|
16 error('data should be of size nnodes * ncases');
|
wolffd@0
|
17 end
|
wolffd@0
|
18
|
wolffd@0
|
19 if nargin < 3, clamped = zeros(n,ncases); end
|
wolffd@0
|
20
|
wolffd@0
|
21 L = 0;
|
wolffd@0
|
22 for i=1:n
|
wolffd@0
|
23 ps = parents(bnet.dag, i);
|
wolffd@0
|
24 e = bnet.equiv_class(i);
|
wolffd@0
|
25 u = find(clamped(i,:)==0);
|
wolffd@0
|
26 ll = log_prob_node(bnet.CPD{e}, cases(i,u), cases(ps,u));
|
wolffd@0
|
27 if approxeq(exp(ll), 0), fprintf('node %d has very low likelihood\n'); end
|
wolffd@0
|
28 L = L + ll;
|
wolffd@0
|
29 end
|
wolffd@0
|
30
|