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