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

W = bnode.glim.w1;
b = bnode.glim.b1;
fam = [bnode.parents bnode.self];

switch bnet.jtree.pot_type
  case 'd',
    assert(subset(bnode.parents, bnet.observed_nodes));
    x = bnet.values(bnode.parents);
    x = x(:)';
    % CPT(i) = Pr(self=i | parents)
    CPT = normalise(exp(x*W + b));
    if ismember(bnode.self, bnet.observed_nodes)
      self_val = bnet.values(bnode.self);
      CPT = CPT(self_val);
    end
    ns = bnet.node_sizes;
    ns(bnet.observed_nodes) = 1;
    pot = mk_table(fam, ns(fam));
    pot.T = myreshape(CPT, pot.sizes);
  case 'g',
    assert(subset(fam, bnet.observed_nodes));
    ns(bnet.observed_nodes) = 0;
    pot = mk_gpot(fam, ns(fam), 'c');
  case 'cg',
    assert(subset(fam, bnet.observed_nodes));
    ns(bnet.observed_nodes) = 0;
    pot = mk_cgpot(bnode.self, bnode.parents, ns, 'c');
  otherwise,
    error('bad type');
end

