function dist = unobs_cond_dist_gaussian(bnode, bnet)
% UNOBS_COND_DIST_GAUSSIAN Compute a Gaussian approx. to Pr(self) for a Gaussian node, assuming the node is not observed.
% dist = unobs_cond_dist_gaussian(bnode, bnet)
%
% If the discrete parents are hidden, we collapse the Conditional Gaussian to a single Gaussian.
% We assume the values of the continuous parents (if any) are known.

ns = bnet.node_sizes;

dps = intersect(bnode.parents, bnet.discrete_nodes);
cps = intersect(bnode.parents, bnet.cts_nodes);
%assert(length(dps)<=1); % just for simplicity
%assert(length(cps)<=1);

if isempty(dps)
  war = 1;
else
  assert(length(dps) == 1);
  obs_dps = intersect(dps, bnet.observed_nodes);
  war = [];
  for i = 1:length(dps)
    dp = dps(i);
    if ismember(dp, obs_dps)
      v = bnet.values(dp);
      w = zeros(1, ns(dp));
      w(v) = 1;
    else
      w = cond_dist_node(bnet, dp);
    end
    war = [war w];
  end
end

if isempty(cps)
  mu = bnode.mean;
else
  if isempty(dps)
    M = 1;
  else
    M = sum(ns(dps));
  end
  mu = zeros(ns(bnode.self), M);
  for i=1:M
    mu(:,i) = bnode.mean(:,i) + bnode.weights(:,:,i) * bnet.values(cps)';
  end
end

[mu, Sigma] = collapse_mog(mu, bnode.cov, war);
dist.mu = mu;
dist.Sigma = Sigma;
