Beispiel #1
0
        /// <summary>
        ///   Computes the optimum number of bins based on a <see cref="BinAdjustmentRule"/>.
        /// </summary>
        ///
        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;
            }
        }
Beispiel #2
0
        /// <summary>
        ///   Computes the optimum number of bins based on a <see cref="BinAdjustmentRule"/>.
        /// </summary>
        /// 
        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;
            }
        }