Mercurial > hg > camir-aes2014
annotate toolboxes/FullBNT-1.0.7/bnt/CPDs/@gaussian_CPD/log_prob_node.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 L = log_prob_node(CPD, self_ev, pev) |
wolffd@0 | 2 % LOG_PROB_NODE Compute prod_m log P(x(i,m)| x(pi_i,m), theta_i) for node i (gaussian) |
wolffd@0 | 3 % L = log_prob_node(CPD, self_ev, pev) |
wolffd@0 | 4 % |
wolffd@0 | 5 % self_ev(m) is the evidence on this node in case m. |
wolffd@0 | 6 % pev(i,m) is the evidence on the i'th parent in case m (if there are any parents). |
wolffd@0 | 7 % (These may also be cell arrays.) |
wolffd@0 | 8 |
wolffd@0 | 9 if iscell(self_ev), usecell = 1; else usecell = 0; end |
wolffd@0 | 10 |
wolffd@0 | 11 use_log = 1; |
wolffd@0 | 12 ncases = length(self_ev); |
wolffd@0 | 13 nparents = length(CPD.sizes)-1; |
wolffd@0 | 14 assert(ncases == size(pev, 2)); |
wolffd@0 | 15 |
wolffd@0 | 16 if ncases == 0 |
wolffd@0 | 17 L = 0; |
wolffd@0 | 18 return; |
wolffd@0 | 19 end |
wolffd@0 | 20 |
wolffd@0 | 21 L = 0; |
wolffd@0 | 22 for m=1:ncases |
wolffd@0 | 23 if isempty(CPD.dps) |
wolffd@0 | 24 i = 1; |
wolffd@0 | 25 else |
wolffd@0 | 26 if usecell |
wolffd@0 | 27 dpvals = cat(1, pev{CPD.dps, m}); |
wolffd@0 | 28 else |
wolffd@0 | 29 dpvals = pev(CPD.dps, m); |
wolffd@0 | 30 end |
wolffd@0 | 31 i = subv2ind(CPD.sizes(CPD.dps), dpvals(:)'); |
wolffd@0 | 32 end |
wolffd@0 | 33 if usecell |
wolffd@0 | 34 y = self_ev{m}; |
wolffd@0 | 35 else |
wolffd@0 | 36 y = self_ev(m); |
wolffd@0 | 37 end |
wolffd@0 | 38 if length(CPD.cps) == 0 |
wolffd@0 | 39 L = L + gaussian_prob(y, CPD.mean(:,i), CPD.cov(:,:,i), use_log); |
wolffd@0 | 40 else |
wolffd@0 | 41 if usecell |
wolffd@0 | 42 x = cat(1, pev{CPD.cps, m}); |
wolffd@0 | 43 else |
wolffd@0 | 44 x = pev(CPD.cps, m); |
wolffd@0 | 45 end |
wolffd@0 | 46 L = L + gaussian_prob(y, CPD.mean(:,i) + CPD.weights(:,:,i)*x, CPD.cov(:,:,i), use_log); |
wolffd@0 | 47 end |
wolffd@0 | 48 end |
wolffd@0 | 49 |