function lam_msg = compute_lambda_msg_mux(bnode, bnet, p)

n = bnode.self;
ns = bnet.node_sizes;
my_lambda = bnet.pearl.msg{n}.lambda(:);
pi_from_inputs = collect_pi_from_inputs(bnode, bnet);

if p == bnode.gate
  W = pi_from_inputs;
else
  j = find_equiv_posns(p, bnode.input); % p is my j'th input
  exclude = j;
  ninputs = length(bnode.input);
  X = bnode.self_size;
  j = bnet.pearl.parent_index{n}(bnode.gate); % gate is my j'th parent
  m = bnet.pearl.msg{n}.pi_from_parent{j};
  pi_from_gate = m(:);
  W = zeros(X, X);
  for x=1:X
    for m=1:X
      pi = pi_from_inputs(x,:)';
      pi(exclude) = (x==m);
      W(x,m) = sum(pi .* pi_from_gate);
    end
  end
end

lam_msg = W' * my_lambda;
