function bnode = update_ess_noisyor(bnode, family_marginal)
% UPDATE_ESS_NOISYOR: Update the Expected Sufficient Statistics of a noisyor node.
% bnode = update_ess_noisyor(bnode, family_marginal)

% We compute the marginals on each parent separately, because of causal independence.
np = length(bnode.parents);
% We must change the domain in case this came from a different member of the equiv. class
family_marginal.domain = [bnode.parents bnode.self];
% x(i) = Prob. parent i is on
x = zeros(1,np);
for i=1:np
  p = marginalize_potential(family_marginal, bnode.parents(i));
  x(i) = p.T(2); % 1 represents off, 2 represents on
  if x(i) ~= 0 | x(i) ~= 1
    bnode.observed_parents = 0;
  end
end
x = [1.0 x]; % add in leak term
% y = prob. I'm on
p = marginalize_potential(family_marginal, bnode.self);
y = p.T(2);

bnode.num_samples = bnode.num_samples + 1;
bnode.parent_vals(bnode.num_samples,:) = x(:)';
bnode.self_vals(bnode.num_samples) = y;

