function [Mu,K,StdTheta,ThetaDev,R] = HoopStats_GetParams(Thetas,Weights)
% "HoopStats_GetParams"
% R01.01
% By Sam Berens (sam.berens@york.ac.uk).
%
% [Mu,K,StdTheta,ThetaDev,R] = HoopStats_GetParams(Thetas,Weights)
%
% Computes various statistics for a sample of angles in radians ("Thetas").
% If optional "Weights" argument is supplied, angles are weighted to have
% varying influences on the statistics;
%
% INPUT:
%   - "Thetas" : an nx1 numeric denoting n angles (in radians);
%   - "Weights" : [Optional] an nx1 numeric denoting weighting values for
%                 each angle;
%
% OUTPUT:
%   - "Mu" : Preferred direction (in radians);
%   - "K" : von Mises concentration parameter;
%   - "StdTheta" : Circular standard deviation;
%   - "ThetaDev" : Circular deviation (spread);
%   - "R" : Resultant vector length;

%% Error check:
if nargin == 1
    Weights = ones(size(Thetas));
elseif nargin > 2
    error('Too many input arguments.');
end
if size(Thetas,2) ~= 1
    error('Input variables ''Thetas'' and ''Weights'' should be nx1 column vectors');
end
if size(Weights,2) ~= 1
    error('Input variables ''Thetas'' and ''Weights'' should be nx1 column vectors');
end
if size(Thetas,1) ~= size(Weights,1)
    error('Input variables ''Thetas'' and ''Weights'' should be nx1 column vectors');
end

%% Computations:
v = exp(Thetas.*1i) .* Weights;
MeanV = sum(v) ./ sum(Weights);
Mu = angle(MeanV);
R = abs(MeanV);
StdTheta = abs(sqrt(2*log(R)/1i)); % exp(i*Var) = R^2;
ThetaDev = sqrt(2-(2*exp(-(StdTheta^2)/2)));
K = HoopStats_R2K(R);

return