Accord.Statistics.Circular.WeightedMean C# (CSharp) Method

WeightedMean() public static method

Computes the Weighted Mean of the given angles.
public static WeightedMean ( double angles, double weights ) : double
angles double A double array containing the angles in radians.
weights double An unit vector containing the importance of each angle /// in . The sum of this array elements should add up to 1.
return double
        public static double WeightedMean(double[] angles, double[] weights)
        {
            double cos = 0, sin = 0;
            for (int i = 0; i < angles.Length; i++)
            {
                cos += Math.Cos(angles[i]) * weights[i];
                sin += Math.Sin(angles[i]) * weights[i];
            }

            return Math.Atan2(sin, cos);
        }