function [g,h,K] = gaussian_cpt_to_canonical(mu, Sigma, B)
% GAUSSIAN_CPT_TO_CANONICAL Convert a linear Gaussian distrib. to a canonical potential.
% [g,h,K] = gaussian_cpt_to_canonical(mu, Sigma, W)

self_size = size(B, 1);
parents_size = size(B, 2);
mu = mu(:);
n = length(mu);
c = normal_coef(Sigma);
if parents_size == 0 
  %[g, h, K] = moment_to_canonical(log(c), mu, Sigma); % COEF
  [g, h, K] = moment_to_canonical(0, mu, Sigma); % this will add the normalizing constant
else
  Sinv = inv(Sigma);
  %g = -0.5*mu'*Sinv*mu -0.5*n*log(2*pi) - 0.5*log(det(Sigma)); 
  g = -0.5*mu'*Sinv*mu + log(c); % COEF
  %g = -0.5*mu'*Sinv*mu;
  h = [-B'*Sinv*mu; Sinv*mu];
  K = [B'*Sinv*B  -B'*Sinv';
           -Sinv*B     Sinv];
end
