pub struct P2Quantile { /* private fields */ }Expand description
Online estimator of a single p-quantile using the P² algorithm.
Tracks five markers — the running minimum, the p/2, p, and (1+p)/2 quantiles, and the running maximum — and adjusts their heights with a piecewise-parabolic (hence “P²”) interpolation as each value arrives. It estimates the quantile in O(1) time and O(1) memory per update without storing or sorting the stream, trading a small approximation error for unbounded scalability.
§Invariants
All state lives in fixed-length arrays (five markers), so
size_of::<P2Quantile>() is constant regardless of how many values have been
consumed — the bounded-memory guarantee.
§Examples
use stats_claw::streaming::P2Quantile;
let mut q = P2Quantile::new(0.5);
for x in 1..=99 {
q.update(f64::from(x));
}
// Median of 1..=99 is 50; P² lands within a couple of integers on this ramp.
assert!((q.value() - 50.0).abs() < 2.0);Implementations§
Source§impl P2Quantile
impl P2Quantile
Sourcepub fn new(p: f64) -> Self
pub fn new(p: f64) -> Self
Creates an estimator for the p-quantile.
§Arguments
p— the quantile probability, expected in[0, 1](e.g.0.5for the median,0.99for the 99th percentile). Values outside the range are not rejected here — the estimate is simply meaningless, mirroring the panic-free convention of the rest of the crate.
§Returns
A fresh estimator with no values consumed; Self::value is 0.0 until
the first Self::update.
Trait Implementations§
Source§impl Clone for P2Quantile
impl Clone for P2Quantile
Source§fn clone(&self) -> P2Quantile
fn clone(&self) -> P2Quantile
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for P2Quantile
impl RefUnwindSafe for P2Quantile
impl Send for P2Quantile
impl Sync for P2Quantile
impl Unpin for P2Quantile
impl UnsafeUnpin for P2Quantile
impl UnwindSafe for P2Quantile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more