Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

streaming-percentiles

2.2.0 • Public • Published

streaming-percentiles

This is a library with implementations of various percentile algorithms on streams of data, with support for the following languages:

  • C++
  • JavaScript

For more on streaming percentiles, see Calculating Percentiles on Streaming Data.

Obtaining the Library

You can download pre-built versions of the library from the streaming-percentiles-cpp releases page. Otherwise see CONTRIBUTING.md for instructions on how to compile the library from source.

Usage Example

C++

Here's a simple example on how to use the Greenwald-Khanna streaming percentile algorithm from C++:

#include <stmpct/gk.hpp>
 
using namespace stmpct;
 
double epsilon = 0.1;
gk g(epsilon);
for (int i = 0; i < 1000; ++i)
    g.insert(rand());
double p50 = g.quantile(0.5); // Approx. median 
double p95 = g.quantile(0.95); // Approx. 95th percentile 

JavaScript

Node.JS

Here's how to use the library from Node.JS:

var sp = require('streaming-percentiles');
 
var epsilon = 0.1;
var g = new sp.GK(epsilon);
for (var i = 0; i < 1000; ++i)
    g.insert(Math.random());
var p50 = g.quantile(0.5); // Approx. median
var p95 = g.quantile(0.95); // Approx. 95th percentile

Browser

Here's how to use the library from a browser. Note that the default module name is streamingPercentiles:

<script src="streamingPercentiles.v1.min.js"></script>
<script>
var epsilon = 0.1;
var gk = new streamingPercentiles.GK(epsilon);
for (var i = 0; i < 1000; ++i)
    g.insert(Math.random());
var p50 = g.quantile(0.5);
</script> 

API Reference

Coming soon!

Contributing

If you are interested in contributing to the library, please see CONTRIBUTING.md.

install

npm i streaming-percentiles

Downloadsweekly downloads

7

version

2.2.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar