Skip to main content

QuantileBinning

Struct QuantileBinning 

Source
pub struct QuantileBinning { /* private fields */ }
Available on crate feature alloc only.
Expand description

Greenwald-Khanna streaming quantile sketch.

Provides epsilon-approximate quantile queries on a data stream using O((1/epsilon) * log(epsilon * N)) space, where N is the number of observed values and epsilon is the error tolerance.

A query for quantile phi returns a value whose true rank r satisfies |r - phi*N| <= epsilon * N.

§Example

let mut sketch = QuantileBinning::new();
for v in 0..1000 {
    sketch.observe(v as f64);
}
let edges = sketch.compute_edges(4);
// edges are approximately at the 25th, 50th, 75th percentiles

Implementations§

Source§

impl QuantileBinning

Source

pub fn new() -> Self

Create a new QuantileBinning with the default epsilon of 0.01 (1% error).

Source

pub fn with_epsilon(epsilon: f64) -> Self

Create a new QuantileBinning with a custom error tolerance.

§Panics

Panics if epsilon is not in the range (0.0, 1.0).

Source

pub fn quantile(&self, phi: f64) -> Option<f64>

Query the approximate value at quantile phi in [0.0, 1.0].

Returns None if the summary is empty.

The returned value has true rank r such that |r - phi*N| <= epsilon * N.

Source

pub fn count(&self) -> u64

Return the number of values observed so far.

Source

pub fn summary_len(&self) -> usize

Return the current number of tuples in the summary.

Trait Implementations§

Source§

impl BinningStrategy for QuantileBinning

Source§

fn observe(&mut self, value: f64)

Observe a single value from the stream.

Source§

fn compute_edges(&self, n_bins: usize) -> BinEdges

Compute bin edges by querying quantiles at evenly spaced positions.

For n_bins bins, queries quantiles at 1/n_bins, 2/n_bins, ..., (n_bins-1)/n_bins and deduplicates adjacent equal edges. Returns at least one edge when data has been observed.

Source§

fn reset(&mut self)

Reset the sketch to its initial empty state (preserving epsilon).

Source§

fn clone_fresh(&self) -> Box<dyn BinningStrategy>

Create a fresh empty instance with the same epsilon.

Source§

impl Clone for QuantileBinning

Source§

fn clone(&self) -> QuantileBinning

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for QuantileBinning

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for QuantileBinning

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.