function bnet = mk_tabular_node(bnet, self, prior)
% MK_TABULAR_NODE Make a node whose conditional distrib. is tabular, with random params.
% bnet = mk_tabular_node(bnet, node_num, prior)
%
% prior = effective sample size of Dirichlet prior.
% Set to 0 to turn off prior. Set to small value (e.g., 0.001) to avoid 0s but without adding too
% much bias.

ps = parents(bnet.adj_mat, self);
ns = bnet.node_sizes;
bnode.type = 'tabular';
bnode.adjustable = 1;
bnode.self = self;
bnode.parents = ps;
bnode.sizes = [ns(ps) ns(self)];
% sum-to-1 constraint reduces the effective num. vals of the node by 1
bnode.nparams = prod([ns(ps) ns(self)-1]);

bnode = randomize_params_tabular(bnode);
bnode = reset_ess_tabular(bnode);

% If each bin has a pseudocount of ess/n (where n = num. bins, ess = effective sample size)
% the total weight in all bins is ess, as required.
num_entries = prod(bnode.sizes);
bnode.prior = myones(bnode.sizes) * (prior/num_entries); 

bnet.bnodes{self} = bnode;
