function pot2 = marginalize_gpot(pot1, onto)
% MARGINALIZE_GPOT Marginalize a Gaussian potential.
% pot2 = marginalize_gpot(pot1, onto)

node_sizes = sparse(1, max(pot1.domain));
node_sizes(pot1.domain) = pot1.sizes;
pot2 = mk_gpot(onto, node_sizes(onto), pot1.subtype);
sum_over = setdiff(pot1.domain, pot2.domain);
keep = pot2.domain;
if pot1.subtype == 'c'
  [pot2.g, pot2.h, pot2.K] = ...
      marginalize_canonical(pot1.g, pot1.h, pot1.K, keep, sum_over, pot1.domain, node_sizes);
else
 [pot2.logp, pot2.mu, pot2.Sigma] = marginalize_gaussian(...
     pot1.logp, pot1.mu, pot1.Sigma, keep, sum_over, pot1.domain, pot1.sizes);
end
