function prob = prob_noisyor(bnode, bnet)
% PROB_NOISYOR Compute the prob. that this noisyor node is on.
% prob = prob_noisyor(bnode, bnet)

fam = [bnode.parents bnode.self];
%assert(subset(fam, bnet.observed_nodes));

parent_vals = bnet.values(bnode.parents);
self_val = bnet.values(bnode.self);

%i = subv2ind(size(bnode.CPT), [parent_vals child_val]);
%prob = bnode.CPT(i);
prob = noisyor_prob(self_val-1, parent_vals-1, bnode.inhibit, 1);

%%%%%%%
function p = noisyor_prob(val, parent_vals, prob_inhibit, leak)
% 0 means off, 1 means on

if leak
  parent_vals = [1 parent_vals];
end
on_parents = find(parent_vals==1);
p = prod(prob_inhibit(on_parents));
if val==1
  p = 1-p;
end

