This is part 4 of my series on calculating percentiles on streaming data.

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:

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:

Pingback: Calculating Percentiles on Streaming Data Part 6: Building a C++ and JavaScript Library from a Single Codebase | Steven Engelhardt, CFA, AIF