Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/general/linear_gaussian_to_cpot.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 pot = linear_gaussian_to_cpot(mu, Sigma, W, domain, ns, cnodes, evidence) | |
2 % LINEAR_GAUSSIAN_TO_CPOT Convert a linear Gaussian CPD to a canonical potential. | |
3 % pot = linear_gaussian_to_cpot(mu, Sigma, W, domain, ns, cnodes, evidence) | |
4 % | |
5 % We include any cts evidence, but ignore any discrete evidence. | |
6 % (Use gaussian_CPD_params_given_dps to use discrete evidence to select mu, Sigma, W.) | |
7 | |
8 odom = domain(~isemptycell(evidence(domain))); | |
9 hdom = domain(isemptycell(evidence(domain))); | |
10 cobs = myintersect(cnodes, odom); | |
11 chid = myintersect(cnodes, hdom); | |
12 cvals = cat(1, evidence{cobs}); | |
13 | |
14 %[g,h,K] = gaussian_to_canonical(mu, Sigma, W); | |
15 Sinv = inv(Sigma); | |
16 g = -0.5*mu'*Sinv*mu + log(normal_coef(Sigma)); | |
17 if isempty(W) | (size(W,2)==0) % no cts parents | |
18 h = Sinv*mu; | |
19 K = Sinv; | |
20 else | |
21 h = [-W'*Sinv*mu; Sinv*mu]; | |
22 K = [W'*Sinv*W -W'*Sinv'; | |
23 -Sinv*W Sinv]; | |
24 end | |
25 | |
26 if ~isempty(cvals) | |
27 %[g, h, K] = enter_evidence_canonical(g, h, K, chid, cobs, cvals(:), ns); | |
28 [hx, hy, KXX, KXY, KYX, KYY] = partition_matrix_vec(h, K, chid, cobs, ns); | |
29 y = cvals(:); | |
30 g = g + hy'*y - 0.5*y'*KYY*y; | |
31 if length(hx)==0 % isempty(X) % i.e., we have instantiated everything away | |
32 h = []; | |
33 K = []; | |
34 else | |
35 h = hx - KXY*y; | |
36 K = KXX; | |
37 end | |
38 end | |
39 | |
40 ns(odom) = 0; | |
41 pot = cpot(domain, ns(domain), g, h, K); | |
42 | |
43 |