annotate toolboxes/FullBNT-1.0.7/bnt/learning/bic_score_family.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 [S, LL] = bic_score(counts, CPT, ncases)
wolffd@0 2 % BIC_SCORE Bayesian Information Criterion score for a single family
wolffd@0 3 % [S, LL] = bic_score(counts, CPT, ncases)
wolffd@0 4 %
wolffd@0 5 % S is a large sample approximation to the log marginal likelihood,
wolffd@0 6 % which can be computed using dirichlet_score.
wolffd@0 7 %
wolffd@0 8 % S = \log [ prod_j _prod_k theta_ijk ^ N_ijk ] - 0.5*d*log(ncases)
wolffd@0 9 % where counts encode N_ijk, theta_ijk is the MLE comptued from counts,
wolffd@0 10 % and d is the num of free parameters.
wolffd@0 11
wolffd@0 12 %CPT = mk_stochastic(counts);
wolffd@0 13 tiny = exp(-700);
wolffd@0 14 LL = sum(log(CPT(:) + tiny) .* counts(:));
wolffd@0 15 % CPT(i) = 0 iff counts(i) = 0 so it is okay to add tiny
wolffd@0 16
wolffd@0 17 ns = mysize(counts);
wolffd@0 18 ns_ps = ns(1:end-1);
wolffd@0 19 ns_self = ns(end);
wolffd@0 20 nparams = prod([ns_ps (ns_self-1)]);
wolffd@0 21 % sum-to-1 constraint reduces the effective num. vals of the node by 1
wolffd@0 22
wolffd@0 23 S = LL - 0.5*nparams*log(ncases);