npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

histogram-simple

v0.0.112

Published

simple 1d histogram util

Downloads

78

Readme

histogram-simple

simple 1d histogram util

Installation

npm i histogram-simple

Usage

var data = [];
for(var i=0;i<10000;i++){
    data.push(Math.random());
}

var SimpleHisto = require('histogram-simple');

//you can override min/max, otherwise it will auto-range to the values in the input array 
//SimpleHisto([data], numberBuckets=10, min=auto, max=auto)
var sh = SimpleHisto(data); 

console.log(sh.result);

//results - normalized, auto-ranged to 10 linear buckets...
// {
//     '0.00014417416554568518': 0.1002,
//     '0.10011602789876432': 0.1015,
//     '0.20008788163198296': 0.1015,
//     '0.3000597353652016': 0.1006,
//     '0.40003158909842024': 0.1043,
//     '0.5000034428316389': 0.0977,
//     '0.5999752965648575': 0.0976,
//     '0.6999471502980762': 0.0997,
//     '0.7999190040312948': 0.1017,
//     '0.8998908577645134': 0.0951
// }

console.log(sh.resultCounts);

//absolute counts per bucket...

// {
//     '0.0000809159023666961': 1038,
//     '0.10006868510259237': 1000,
//     '0.20005645430281804': 946,
//     '0.3000442235030437': 968,
//     '0.4000319927032694': 997,
//     '0.5000197619034951': 1026,
//     '0.6000075311037207': 996,
//     '0.6999953003039464': 1011,
//     '0.7999830695041721': 1024,
//     '0.8999708387043976': 993
// }

//generate random number with similar distribution to this histogram 
//sh.random(randomFunc=Math.random); //specificy randomFunc if you want seedable random etc
console.log(sh.random());
//0.34752809779407723

//get probability density function pdf(x) for this histogram [qunatized to the buckets, no interpolation]
console.log(sh.pdf(-0.05)); //0.0
console.log(sh.pdf(0.5)); //0.10093
console.log(sh.pdf(1.05)); //0.0

//print graphically to console, simple ascii graph...

console.log(sh.toString()) //toString(fullWidth=20)

// 0.0000: ##
// 0.1000: ##
// 0.2000: ##
// 0.3000: #
// 0.4000: #
// 0.5000: #
// 0.6000: #
// 0.7000: ##
// 0.8000: #
// 0.9000: ##

// all fields...
// sh.data = data;
// sh.dataMax = Math.max(...sh.data);
// sh.dataMin = Math.min(...sh.data);
// sh.numBuckets = numBuckets;
// sh.buckets = {}; //for internal use, indexed 0...n, absolute counts
// sh.bucketsFreqs = {}; //for internal use, indexed 0...n, normalized
// sh.dataRange = (sh.dataMax-sh.dataMin);
// sh.bucketLabels = ['field names from bucketsLabelled']
// sh.bucketsLabelled = { '0.00006862812315966416': 123 ... } //absolute counts
// sh.bucketsFreqsLabelled = { '0.00006862812315966416': 0.1001 ... } //normalized frequencies
// sh.result = sh.bucketsFreqsLabelled //just an alias
// sh.resultCounts = sh.bucketsLabelled //just an alias

stonks