public static int NumberOfBins(double[] values, DoubleRange range, BinAdjustmentRule rule)
{
switch (rule)
{
case BinAdjustmentRule.None:
return 0;
case BinAdjustmentRule.Scott:
double h = (3.49 * Measures.StandardDeviation(values))
/ System.Math.Pow(values.Length, 1.0 / 3.0);
return (int)Math.Ceiling(range.Length / h);
case BinAdjustmentRule.Sturges:
return (int)Math.Ceiling(Math.Log(values.Length, 2));
case BinAdjustmentRule.SquareRoot:
return (int)Math.Floor(Math.Sqrt(values.Length));
default:
goto case BinAdjustmentRule.SquareRoot;
}
}