about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/KPMstats/condGaussToJoint.m
blob: 59075675cc4447defd53455610c5ae90f1701567 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function [muXY, SigmaXY] = condGaussToJoint(muX, SigmaX, muY, SigmaY, WYgivenX)

% Compute P(X,Y) from P(X) * P(Y|X) where P(X)=N(X;muX,SigmaX) 
% and P(Y|X) = N(Y; WX + muY, SigmaY)

% For details on how to compute a Gaussian from a Bayes net
% - "Gaussian Influence Diagrams", R. Shachter and C. R. Kenley, Management Science, 35(5):527--550, 1989.

% size(W) = dy x dx
dx = length(muX);
dy = length(muY);
muXY = [muX(:); WYgivenX*muX(:) + muY];

W = [zeros(dx,dx) WYgivenX';
     zeros(dy,dx) zeros(dy,dy)];
D = [SigmaX       zeros(dx,dy);
     zeros(dy,dx) SigmaY];

U = inv(eye(size(W)) - W')';
SigmaXY = U' * D * U;