Computes histogram bin counts for an array of values.
Compute Histogram
===
> Computes histogram bins for an array of values.
`` bash`
$ npm install compute-histogram
To use the module,
` javascript`
var computeHistogram = require( 'compute-histogram' );
#### computeHistogram(arr)
Computes the histogram for the provided input array. Returns a two dimensional array. The first dimension is the bin
index. The second dimension is the number of items in the bin.
` javascript
var arr = [ 8, 2, 3, 9, 5, 1, 4, 10, 7, 0, 6 ];
var r = computeHistogram(arr);
// [ [ 0, 2 ], [ 1, 2 ], [ 2, 2 ], [ 3, 2 ], [ 4, 3 ] ]
`
#### computeHistogram(arr, numBins)
If numBins isn't specified or is set to zero, the number of bins is automatically
computed using the maximum of the Sturges and
Freedman–Diaconis' choice methods.
Otherwise the histogram for the provided input array and binSize is computed.
` javascript
var arr = [ 8, 2, 3, 9, 5, 1, 4, 10, 7, 0, 6 ];
var r = computeHistogram(arr, 5);
// [ [ 0, 2 ], [ 1, 2 ], [ 2, 2 ], [ 3, 2 ], [ 4, 3 ] ]
`
#### computeHistogram(arr, numBins, trimTailPercentage)
Computes the histogram for the provided input array and binSize. This also trims a percertage from eachtrimTailPercentage
end of the distribution using to allow filtering of outliers.
` javascript
var arr = [ 8, 2, 3, 9, 5, 1, 4, 10, 7, 0, 6 ];
var r = computeHistogram(arr, 5, .05);
// [ [ 0, 2 ], [ 1, 2 ], [ 2, 2 ], [ 3, 2 ], [ 4, 2 ] ]
``
The automatic bin size heuristic is based on NumPy's
implementation
---
Copyright © 2018-2021. Christopher Baus.