Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/CPDs/@gaussian_CPD/Old/CPD_to_lambda_msg.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 lam_msg = CPD_to_lambda_msg(CPD, msg_type, n, ps, msg, p) | |
2 % CPD_TO_LAMBDA_MSG Compute lambda message (gaussian) | |
3 % lam_msg = compute_lambda_msg(CPD, msg_type, n, ps, msg, p) | |
4 % Pearl p183 eq 4.52 | |
5 | |
6 switch msg_type | |
7 case 'd', | |
8 error('gaussian_CPD can''t create discrete msgs') | |
9 case 'g', | |
10 self_size = CPD.sizes(end); | |
11 if all(msg{n}.lambda.precision == 0) % no info to send on | |
12 lam_msg.precision = zeros(self_size); | |
13 lam_msg.info_state = zeros(self_size, 1); | |
14 return; | |
15 end | |
16 cpsizes = CPD.sizes(CPD.cps); | |
17 dpval = 1; | |
18 Q = CPD.cov(:,:,dpval); | |
19 Sigmai = Q; | |
20 wmu = zeros(self_size, 1); | |
21 for k=1:length(ps) | |
22 pk = ps(k); | |
23 if pk ~= p | |
24 bk = block(k, cpsizes); | |
25 Bk = CPD.weights(:, bk, dpval); | |
26 m = msg{n}.pi_from_parent{k}; | |
27 Sigmai = Sigmai + Bk * m.Sigma * Bk'; | |
28 wmu = wmu + Bk * m.mu; % m.mu = u(k) | |
29 end | |
30 end | |
31 % Sigmai = Q + sum_{k \neq i} B_k Sigma_k B_k' | |
32 i = find_equiv_posns(p, ps); | |
33 bi = block(i, cpsizes); | |
34 Bi = CPD.weights(:,bi, dpval); | |
35 | |
36 if 0 | |
37 P = msg{n}.lambda.precision; | |
38 if isinf(P) % inv(P)=Sigma_lambda=0 | |
39 precision_temp = inv(Sigmai); | |
40 lam_msg.precision = Bi' * precision_temp * Bi; | |
41 lam_msg.info_state = precision_temp * (msg{n}.lambda.mu - wmu); | |
42 else | |
43 A = inv(P + inv(Sigmai)); | |
44 precision_temp = P + P*A*P; | |
45 lam_msg.precision = Bi' * precision_temp * Bi; | |
46 self_size = length(P); | |
47 C = eye(self_size) + P*A; | |
48 z = msg{n}.lambda.info_state; | |
49 lam_msg.info_state = C*z - C*P*wmu; | |
50 end | |
51 end | |
52 | |
53 if isinf(msg{n}.lambda.precision) | |
54 Sigma_lambda = zeros(self_size, self_size); % infinite precision => 0 variance | |
55 mu_lambda = msg{n}.lambda.mu; % observed_value; | |
56 else | |
57 Sigma_lambda = inv(msg{n}.lambda.precision); | |
58 mu_lambda = Sigma_lambda * msg{n}.lambda.info_state; | |
59 end | |
60 precision_temp = inv(Sigma_lambda + Sigmai); | |
61 lam_msg.precision = Bi' * precision_temp * Bi; | |
62 lam_msg.info_state = Bi' * precision_temp * (mu_lambda - wmu); | |
63 end | |
64 |