wolffd@0: function L = log_lik_complete(bnet, cases, clamped) wolffd@0: % 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: % L = log_lik_complete(bnet, cases, clamped) wolffd@0: % wolffd@0: % If there is a missing data, you must use an inference engine. wolffd@0: % cases(i,m) is the value assigned to node i in case m. wolffd@0: % (If there are vector-valued nodes, cases should be a cell array.) wolffd@0: % clamped(i,m) = 1 if node i was set by intervention in case m (default: clamped = zeros) wolffd@0: % Clamped nodes contribute a factor of 1.0 to the likelihood. wolffd@0: wolffd@0: if iscell(cases), usecell = 1; else usecell = 0; end wolffd@0: wolffd@0: n = length(bnet.dag); wolffd@0: ncases = size(cases, 2); wolffd@0: if n ~= size(cases, 1) wolffd@0: error('data should be of size nnodes * ncases'); wolffd@0: end wolffd@0: wolffd@0: if nargin < 3, clamped = zeros(n,ncases); end wolffd@0: wolffd@0: L = 0; wolffd@0: for i=1:n wolffd@0: ps = parents(bnet.dag, i); wolffd@0: e = bnet.equiv_class(i); wolffd@0: u = find(clamped(i,:)==0); wolffd@0: L = L + log_prob_node(bnet.CPD{e}, cases(i,u), cases(ps,u)); wolffd@0: end wolffd@0: