annotate toolboxes/FullBNT-1.0.7/bnt/general/log_marg_lik_complete.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function L = log_marg_lik_complete(bnet, cases, clamped)
wolffd@0 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
wolffd@0 3 % L = log_marg_lik_complete(bnet, cases, clamped)
wolffd@0 4 %
wolffd@0 5 % This differs from log_lik_complete because we integrate out the parameters.
wolffd@0 6 % If there is a missing data, you must use an inference engine.
wolffd@0 7 % cases(i,m) is the value assigned to node i in case m.
wolffd@0 8 % (If there are vector-valued nodes, cases should be a cell array.)
wolffd@0 9 % clamped(i,m) = 1 if node i was set by intervention in case m (default: clamped = zeros)
wolffd@0 10 % Clamped nodes contribute a factor of 1.0 to the likelihood.
wolffd@0 11 %
wolffd@0 12 % If there is a single case, clamped is a list of the clamped nodes, not a bit vector.
wolffd@0 13
wolffd@0 14 if iscell(cases), usecell = 1; else usecell = 0; end
wolffd@0 15
wolffd@0 16 n = length(bnet.dag);
wolffd@0 17 ncases = size(cases, 2);
wolffd@0 18 if n ~= size(cases, 1)
wolffd@0 19 error('data should be of size nnodes * ncases');
wolffd@0 20 end
wolffd@0 21
wolffd@0 22 if ncases == 1
wolffd@0 23 if nargin < 3, clamped = []; end
wolffd@0 24 clamp_set = clamped;
wolffd@0 25 clamped = zeros(n,1);
wolffd@0 26 clamped(clamp_set) = 1;
wolffd@0 27 else
wolffd@0 28 if nargin < 3, clamped = zeros(n,ncases); end
wolffd@0 29 end
wolffd@0 30
wolffd@0 31 L = 0;
wolffd@0 32 for i=1:n
wolffd@0 33 ps = parents(bnet.dag, i);
wolffd@0 34 e = bnet.equiv_class(i);
wolffd@0 35 u = find(clamped(i,:)==0);
wolffd@0 36 L = L + log_marg_prob_node(bnet.CPD{e}, cases(i,u), cases(ps,u));
wolffd@0 37 end
wolffd@0 38
wolffd@0 39
wolffd@0 40