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