Accord.Statistics.Visualizations.Histogram.NumberOfBins C# (CSharp) Method

NumberOfBins() public static method

Computes the optimum number of bins based on a BinAdjustmentRule.
public static NumberOfBins ( double values, DoubleRange range, BinAdjustmentRule rule ) : int
values double
range AForge.DoubleRange
rule BinAdjustmentRule
return int
        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;
            }
        }