#quantile #p2 #psqr

p-square

The P-Square (P2) algorithm for dynamic calculation of quantiles without storing observations

2 releases

Uses new Rust 2024

0.1.1 Mar 26, 2026
0.1.0 Mar 26, 2026

#1377 in Algorithms

MIT license

11KB
182 lines

The P-Square (P2) algorithm for dynamic calculation of quantiles without storing observations.

An implementation based on the algorithm described in this paper.

This algorithm calculates estimates for percentiles of observations sets dynamically, with a O(1) space complexity.

Examples

#
let mut p2 = P2::new(0.3);

for n in 1..=100 {
    p2.feed(n as f64);
}

assert_eq!(p2.estimate(), 30.0);

P-Square

Crates.io Documentation Tests

The P-Square (P2) algorithm for dynamic calculation of quantiles without storing observations.

See the paper for more about the algorithm.

See the documentation.

License

Licensed under the MIT license (LICENSE or http://opensource.org/licenses/MIT).

No runtime deps