Giter Club home page Giter Club logo

compute-histogram's Introduction

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.

compute-histogram's People

Contributors

baus avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.