function bnet = update_var_marginals(bnet)
% UPDATE_VAR_MARGINALS Update the posteriors on each logistic node and its parents.
% bnet = update_var_marginals(bnet)

num_nodes = length(bnet.adj_mat);
ns = bnet.node_sizes;
for i=1:num_nodes
  if ~ismember(i, bnet.observed_nodes)
    m = marginal_nodes(bnet, i);
    if ismember(i, bnet.cts_nodes)
      bnet.jtree.hybrid.marginal{i}.mu = m.mu;
      bnet.jtree.hybrid.marginal{i}.Sigma = m.Sigma;
      fprintf('updating %d, mu %5.3f, Sigma %5.3f\n', i, m.mu, m.Sigma);
    else
      %if strcmp(bnet.bnodes{bnet.equiv_class(i)}.type, 'logistic')
      %	bnet.jtree.hybrid.marginal{i}.prob_true = m.T(2);
      %end
      fprintf('updating %d, P(true)=%5.3f\n', i, m.T(2));
      bnet.values(i) = argmax(m.T);
    end
  end
end
bnet.jtree.hybrid.var_iter = bnet.jtree.hybrid.var_iter + 1;
