diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/toolboxes/FullBNT-1.0.7/bnt/learning/bic_score_family.m	Tue Feb 10 15:05:51 2015 +0000
@@ -0,0 +1,23 @@
+function [S, LL] = bic_score(counts, CPT, ncases)
+% BIC_SCORE Bayesian Information Criterion score for a single family
+% [S, LL] = bic_score(counts, CPT, ncases)
+%
+% S is a large sample approximation to the log marginal likelihood,
+% which can be computed using dirichlet_score.
+%
+% S  = \log [ prod_j _prod_k theta_ijk ^ N_ijk ]  - 0.5*d*log(ncases) 
+% where counts encode N_ijk, theta_ijk is the MLE comptued from counts,
+% and d is the num of free parameters.
+
+%CPT = mk_stochastic(counts);
+tiny = exp(-700);
+LL = sum(log(CPT(:)  + tiny) .* counts(:));
+% CPT(i) = 0 iff counts(i) = 0 so it is okay to add tiny
+
+ns = mysize(counts);
+ns_ps = ns(1:end-1);
+ns_self = ns(end);
+nparams = prod([ns_ps (ns_self-1)]);
+% sum-to-1 constraint reduces the effective num. vals of the node by 1
+
+S = LL - 0.5*nparams*log(ncases);