compute-histogram

0.9.11 • Public • Published

Compute Histogram

Computes histogram bins for an array of values.

Installation

$ npm install compute-histogram

Usage

To use the module,

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.

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.

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 each end of the distribution using trimTailPercentage to allow filtering of outliers.

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 ] ]

Notes

The automatic bin size heuristic is based on NumPy's implementation

License

MIT license.


Copyright

Copyright © 2018-2021. Christopher Baus.

Package Sidebar

Install

npm i compute-histogram

Weekly Downloads

354

Version

0.9.11

License

MIT

Unpacked Size

21.3 kB

Total Files

8

Last publish

Collaborators

  • chrisbaus