function negloglikelihood = NLLF_gaussian(params,data)

if length(params) ==1
   % If the function is supplied only with SD, set mean to zero
   mean = 0;
   SD = params;
elseif length(params) == 2
   mean = params(1);
   SD = params(2);
elseif length(params) ~= 2
   error('Need 2 parameters in NLLF_gaussian (mean, SD)')
end

PDF = 1./sqrt(2*pi) / SD .* exp(-(data-mean).^2./2./SD.^2);

if any(PDF==0)
   negloglikelihood = Inf;
else
   logPDF = log(PDF);
   negloglikelihood = -sum(logPDF);
end
