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