annotate toolboxes/FullBNT-1.0.7/bnt/inference/static/@gaussian_inf_engine/private/extract_params_from_gbn.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [B,D,mu] = extract_params_from_gbn(bnet)
wolffd@0 2 % Extract all the local parameters of each Gaussian node, and collect them into global matrices.
wolffd@0 3 % [B,D,mu] = extract_params_from_gbn(bnet)
wolffd@0 4 %
wolffd@0 5 % B(i,j) is a block matrix that contains the transposed weight matrix from node i to node j.
wolffd@0 6 % D(i,i) is a block matrix that contains the noise covariance matrix for node i.
wolffd@0 7 % mu(i) is a block vector that contains the shifted noise mean for node i.
wolffd@0 8
wolffd@0 9 % In Shachter's model, the mean of each node in the global gaussian is
wolffd@0 10 % the same as the node's local unconditional mean.
wolffd@0 11 % In Alag's model (which we use), the global mean gets shifted.
wolffd@0 12
wolffd@0 13
wolffd@0 14 num_nodes = length(bnet.dag);
wolffd@0 15 bs = bnet.node_sizes(:); % bs = block sizes
wolffd@0 16 N = sum(bs); % num scalar nodes
wolffd@0 17
wolffd@0 18 B = zeros(N,N);
wolffd@0 19 D = zeros(N,N);
wolffd@0 20 mu = zeros(N,1);
wolffd@0 21
wolffd@0 22 for i=1:num_nodes % in topological order
wolffd@0 23 ps = parents(bnet.dag, i);
wolffd@0 24 e = bnet.equiv_class(i);
wolffd@0 25 %[m, Sigma, weights] = extract_params_from_CPD(bnet.CPD{e});
wolffd@0 26 s = struct(bnet.CPD{e}); % violate privacy of object
wolffd@0 27 m = s.mean; Sigma = s.cov; weights = s.weights;
wolffd@0 28 if length(ps) == 0
wolffd@0 29 mu(block(i,bs)) = m;
wolffd@0 30 else
wolffd@0 31 mu(block(i,bs)) = m + weights * mu(block(ps,bs));
wolffd@0 32 end
wolffd@0 33 B(block(ps,bs), block(i,bs)) = weights';
wolffd@0 34 D(block(i,bs), block(i,bs)) = Sigma;
wolffd@0 35 end
wolffd@0 36
wolffd@0 37
wolffd@0 38