Have opinions about JavaScript? We want to hear them. Take the 2018 JavaScript Ecosystem Survey »

compute-histogram

0.9.6 • 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. Christopher Baus.

install

npm i compute-histogram

Downloadsweekly downloads

8

version

0.9.6

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability