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

compute() private method

Actually computes the histogram.
private compute ( double values ) : void
values double
return void
        private void compute(double[] values)
        {
            int numberOfBins = this.values.Length;
            DoubleRange scale = new DoubleRange(0, numberOfBins);
            DoubleRange range = Range;

            if (range.Length == 0)
            {
                if (values.Length > 0)
                    this.values[0] = values.Length;
                return;
            }

            // Populate Bins
            for (int i = 0; i < values.Length; i++)
            {
                double v = values[i];

                // Convert the value to the range of histogram
                //  bins to check which bin the value belongs.
                int index = (int)Vector.Scale(v, range, scale);

                if (index < numberOfBins)
                    this.values[index]++;
                else if (inclusiveUpperBound)
                    this.values[numberOfBins - 1]++;
            }


            // If this is a cumulative histogram,
            //  accumulate values in the bins.
            if (cumulative)
            {
                for (int i = 1; i < this.values.Length; i++)
                    this.values[i] += this.values[i - 1];
            }
        }