function [Pd,Nll] = HoopStats_VonmFit(Mu,K,Thetas)
% "HoopStats_VonmFit"
% R01.01
% By Sam Berens (sam.berens@york.ac.uk).
%
% [Pd,Nll] = HoopStats_VonmFit(Mu,K,Thetas)
%
% Compute values of the von Mises probability density function ("Pd") and
% the associated negative log-likelihood (Nll) for angles ("Thetas", in
% radians) drawn from a distribution with mean "Mu" and concentration "K";

%% Error check:
if nargin > 3
    error('Too many input arguments.');
elseif nargin < 3
    error('Too few input arguments.');
end
if numel(Mu) ~= 1
    error('Input ''Mu'' should be scalar.');
end
if numel(K) ~= 1
    error('Input ''K'' should be scalar.');
end
if size(Thetas,2) ~= 1
    error('Input variable ''Theta'' should be nx1 column vectors');
end

%% Evaluate PDF:
C = 1/(2*pi*besseli(0,K));
Pd = C * exp(K*cos(Thetas-Mu));

%% Now compute the NLL:
Nll = -sum(log(Pd));

return