Calculating Percentiles on Streaming Data Part 4: JavaScript Library
Calculating Percentiles on Streaming Data
Published: 2018-03-08
Calculating Percentiles on Streaming Data Part 4: JavaScript Library

This is part 4/8 of my Calculating Percentiles on Streaming Data series.

I have created a reusable JavaScript library which contains my implementation of the streaming percentile algorithms found within this blog post and published it to GitHub and NPM. Here’s what using it looks like:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
var sp = require("streaming-percentiles');

// epsilon is allowable error. As epsilon becomes smaller, the
// accuracy of the approximations improves, but the class consumes
// more memory.
var epsilon = 0.1;
var gk = new sp.GK(epsilon);
for (var i = 0; i < 1000; ++i)
    gk.insert(Math.random());
var p50 = gk.quantile(0.5); // Approx. median
var p95 = gk.quantile(0.95); // Approx. 95th percentile

You can find it here: