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