function pot = mk_pot_from_softmax(bnode, bnet, discrete, order)
% MK_POT_FROM_SOFTMAX Make a potential from a softmax node.
% pot = mk_pot_from_softmax(bnode, bnet, discrete, order)

if discrete
  if order == -1 % not a hybrid 
    assert(subset(bnode.parents, bnet.observed_nodes));
    x = bnet.values(bnode.parents);
    x = x(:)';
  else
    % Find a clique that I've already visited which contains my parents.
    % Regard their most probable value as their true value.
    [c, cs] = find_clique(bnet.jtree, bnode.parents);
    cs = intersect(cs, bnet.jtree.postorder(1:order));
    m = marginal_nodes(bnet, bnode.parents, 1, cs(1));
    x = m.mu(:)';
  end
  % CPT(i) = Pr(self=i | parents)
  if ismember(bnode.self, bnet.observed_nodes)
    CPT = 1;
  else
    W = bnode.glim.w1;
    b = bnode.glim.b1;
    CPT = normalise(exp(x*W + b));
  end
  ns = bnet.node_sizes;
  ns(bnet.observed_nodes) = 1;
  fam = [bnode.parents bnode.self];
  pot = mk_table(fam, ns(fam));
  pot.T = myreshape(CPT, pot.sizes);
else
  if ismember(bnode.self, bnet.observed_nodes)
    % log Pr(self | parents, ev) = 0, since I'm observed
    ns = bnet.node_sizes;
    ns(bnet.observed_nodes) = 0;
    fam = [bnode.parents bnode.self];
    pot = mk_gpot(fam, ns(fam), 'c');
  else
    error('!');
  end
end

