function [pot, lik] = normalize_gpot(pot)
% NORMALIZE_POT Convert the potential Pr(X,E) into Pr(X|E) and return Pr(E).
% [pot, lik] = normalize_gpot(pot)

pot1 = can_to_mom(pot);
    
% Marginalize down to [], so that the normalizing constant becomes Pr(E)
loglik = marginalize_gaussian(pot1.logp, pot1.mu, pot1.Sigma, [], pot1.domain, pot1.domain, pot1.sizes);
lik = exp(loglik);

% Adjust scale factor to reflect the fact that the pot now represents Pr(X | E) instead of Pr(X, E).
switch pot.subtype
  case 'c',
    pot.g = pot.g - loglik;
  case 'm'
    pot.logp = pot.logp - loglik;
end

