Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/CPDs/@gaussian_CPD/Old/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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function L = log_prob_node(CPD, self_ev, pev) | |
2 % LOG_PROB_NODE Compute prod_m log P(x(i,m)| x(pi_i,m), theta_i) for node i (gaussian) | |
3 % L = log_prob_node(CPD, self_ev, pev) | |
4 % | |
5 % self_ev(m) is the evidence on this node in case m. | |
6 % pev(i,m) is the evidence on the i'th parent in case m (if there are any parents). | |
7 % (These may also be cell arrays.) | |
8 | |
9 if iscell(self_ev), usecell = 1; else usecell = 0; end | |
10 | |
11 use_log = 1; | |
12 ncases = length(self_ev); | |
13 nparents = length(CPD.sizes)-1; | |
14 assert(ncases == size(pev, 2)); | |
15 | |
16 if ncases == 0 | |
17 L = 0; | |
18 return; | |
19 end | |
20 | |
21 if length(CPD.dps)==0 % no discrete parents, so we can vectorize | |
22 i = 1; | |
23 if usecell | |
24 Y = cell2num(self_ev); | |
25 else | |
26 Y = self_ev; | |
27 end | |
28 if length(CPD.cps) == 0 | |
29 L = gaussian_prob(Y, CPD.mean(:,i), CPD.cov(:,:,i), use_log); | |
30 else | |
31 if usecell | |
32 X = cell2num(pev); | |
33 else | |
34 X = pev; | |
35 end | |
36 L = gaussian_prob(Y, CPD.mean(:,i) + CPD.weights(:,:,i)*X, CPD.cov(:,:,i), use_log); | |
37 end | |
38 else % each case uses a (potentially) different set of parameters | |
39 L = 0; | |
40 for m=1:ncases | |
41 if usecell | |
42 dpvals = cat(1, pev{CPD.dps, m}); | |
43 else | |
44 dpvals = pev(CPD.dps, m); | |
45 end | |
46 i = subv2ind(CPD.sizes(CPD.dps), dpvals(:)'); | |
47 y = self_ev{m}; | |
48 if length(CPD.cps) == 0 | |
49 L = L + gaussian_prob(y, CPD.mean(:,i), CPD.cov(:,:,i), use_log); | |
50 else | |
51 if usecell | |
52 x = cat(1, pev{CPD.cps, m}); | |
53 else | |
54 x = pev(CPD.cps, m); | |
55 end | |
56 L = L + gaussian_prob(y, CPD.mean(:,i) + CPD.weights(:,:,i)*x, CPD.cov(:,:,i), use_log); | |
57 end | |
58 end | |
59 end |