pub struct QuantileBinning { /* private fields */ }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 percentilesImplementations§
Source§impl QuantileBinning
impl QuantileBinning
Sourcepub fn with_epsilon(epsilon: f64) -> Self
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).
Sourcepub fn quantile(&self, phi: f64) -> Option<f64>
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.
Sourcepub fn summary_len(&self) -> usize
pub fn summary_len(&self) -> usize
Return the current number of tuples in the summary.
Trait Implementations§
Source§impl BinningStrategy for QuantileBinning
impl BinningStrategy for QuantileBinning
Source§fn compute_edges(&self, n_bins: usize) -> BinEdges
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 clone_fresh(&self) -> Box<dyn BinningStrategy>
fn clone_fresh(&self) -> Box<dyn BinningStrategy>
Create a fresh empty instance with the same epsilon.
Source§impl Clone for QuantileBinning
impl Clone for QuantileBinning
Source§fn clone(&self) -> QuantileBinning
fn clone(&self) -> QuantileBinning
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more