function y = mvnpdftestbss(x,mu,sigma)
%MVNPDFTESTBSS Compute the values for the multivariate normal PDF.
%
% INPUTS:
%
%    x:
%        A scalar value, column vector, or matrix of points, as the rows,
%        at which the multivariate normal distribution is to be evaluated.
%
%     mu:
%        The mean vector for the multivariate normal distribution. If not
%        present a mean vector of zeros is used.
%
%     sigma:
%         The covariance matrix for the multivariate normal distribution.
%         If not present a diagonal identity matrix is used.
%
% OUTPUTS:
%
%    y: 
%        Output values for the multivariate normal distribution evalueated
%        at the points in x using the supplied mean vector and covariance
%        matrix or the default values.
%

%
% Copyright 2014-2018 Biometrics Northwest LLC
%

%
% Modified: 2018-08-24
% Author  : Kevin R. Gehringer
%
%     Added documentation and an error check on the input.
%
% Created: 2014-11-25
% Author : Kevin R. Gehringer
%

if (~(isrow(x) || ismatrix(x)) )
    error('The input must be a row vector or a matrix whos rows are the points.');
end

[n,m] = size(x);

switch nargin
   case 1
      mymu    = zeros(1,m);
      mysigma = eye(m);
   case 2
      mymu    = mu;
      mysigma = eye(m);
   case 3
      mymu    = mu;
      mysigma = sigma;
   otherwise
      error('incorrect number of arguments');
end

k = det(chol(mysigma))*(sqrt(2*pi))^m;
y = zeros(n,1);

nmym = size(mymu,1);
if(nmym>1)
   mymu = mymu';
end

sinv = inv(mysigma);

for i = 1:n
   y(i) = (1/k)*exp(-(1/2)*(x(i,:)-mymu)*sinv*(x(i,:)-mymu)');
end
