function ll = log_likelihood_tabular(bnode)
% LOG_LIKELIHOOD_TABULAR Compute the contribution to the total expected log-likelihood of a tabular node.
% ll = log_likelihood_tabular(bnode)

% The prob of data cases (X=x1, X=x2, X=x1, X=x1)  is Pr(X=x1)^3 * Pr(X=x2).
% Hence the log prob is \sum_xi N(X=xi) * log(Pr(X=xi)), where N(X=xi) is the (expected) number of times
% this event occurs in the data set.

tiny = exp(-700);
ll = log(bnode.CPT(:)  + tiny)' * bnode.counts(:); % CPT(i) = 0 iff counts(i) = 0
