annotate toolboxes/FullBNT-1.0.7/bnt/general/score_bnet_complete.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function L = log_lik_complete(bnet, cases, clamped)
Daniel@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
Daniel@0 3 % L = log_lik_complete(bnet, cases, clamped)
Daniel@0 4 %
Daniel@0 5 % If there is a missing data, you must use an inference engine.
Daniel@0 6 % cases(i,m) is the value assigned to node i in case m.
Daniel@0 7 % (If there are vector-valued nodes, cases should be a cell array.)
Daniel@0 8 % clamped(i,m) = 1 if node i was set by intervention in case m (default: clamped = zeros)
Daniel@0 9 % Clamped nodes contribute a factor of 1.0 to the likelihood.
Daniel@0 10
Daniel@0 11 if iscell(cases), usecell = 1; else usecell = 0; end
Daniel@0 12
Daniel@0 13 n = length(bnet.dag);
Daniel@0 14 ncases = size(cases, 2);
Daniel@0 15 if n ~= size(cases, 1)
Daniel@0 16 error('data should be of size nnodes * ncases');
Daniel@0 17 end
Daniel@0 18
Daniel@0 19 if nargin < 3, clamped = zeros(n,ncases); end
Daniel@0 20
Daniel@0 21 L = 0;
Daniel@0 22 for i=1:n
Daniel@0 23 ps = parents(bnet.dag, i);
Daniel@0 24 e = bnet.equiv_class(i);
Daniel@0 25 u = find(clamped(i,:)==0);
Daniel@0 26 L = L + log_prob_node(bnet.CPD{e}, cases(i,u), cases(ps,u));
Daniel@0 27 end
Daniel@0 28