%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Analytical expression of the log likelihood
% of the data on which a single Gaussian is fitted
%
% mu: mean
% sigma: std dev
% n is the number of samples

function log_lkld = log_lkld_single_gaussian( mu, sigma, n, unbiased )

  if nargin < 3
    error( [ mfilename '.log_lkld_single_gaussian() needs at least 3 input arguments.' ] );
  end

  if ~exist( 'unbiased', 'var' )
    unbiased = 1;
  end

  d = numel( mu );

  log_lkld = - n * d / 2 * log( 2 * pi ) - n / 2 * log( abs( det( sigma ) ) );

  if unbiased
    log_lkld = log_lkld - ( n - 1 ) * d / 2;
  else
    log_lkld = log_lkld - n * d / 2;
  end
  
