comparison toolboxes/FullBNT-1.0.7/bnt/general/score_bnet_complete.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
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