pub struct TDigest { /* private fields */ }Expand description
T-Digest to be operated on.
Implementations§
Source§impl TDigest
impl TDigest
pub fn new(max_size: usize) -> Self
pub fn new_with_centroid(max_size: usize, centroid: Centroid) -> Self
pub fn count(&self) -> f64
pub fn max(&self) -> f64
pub fn min(&self) -> f64
pub fn max_size(&self) -> usize
Sourcepub fn centroids(&self) -> &[Centroid]
pub fn centroids(&self) -> &[Centroid]
The centroids that make up this digest, ordered by mean.
Together with the Self::sum(), Self::max_size(),
Self::count(), Self::max(), and Self::min() accessors this
exposes the full serialized state of the digest without packing it into
a ScalarValue list. See Self::try_from_parts() for the inverse.
Source§impl TDigest
impl TDigest
pub fn merge_unsorted_f64(&self, unsorted_values: Vec<f64>) -> TDigest
pub fn merge_sorted_f64(&self, sorted_values: &[f64]) -> TDigest
pub fn merge_digests<'a>( digests: impl IntoIterator<Item = &'a TDigest>, ) -> TDigest
Sourcepub fn estimate_quantile(&self, q: f64) -> f64
pub fn estimate_quantile(&self, q: f64) -> f64
To estimate the value located at q quantile
Sourcepub fn to_scalar_state(&self) -> Vec<ScalarValue>
pub fn to_scalar_state(&self) -> Vec<ScalarValue>
This method decomposes the TDigest and its Centroid instances
into a series of primitive scalar values.
First the values of the TDigest are packed, followed by the variable
number of centroids packed into a ScalarValue::List of
ScalarValue::Float64:
┌────────┬────────┬────────┬───────┬────────┬────────┐
│max_size│ sum │ count │ max │ min │centroid│
└────────┴────────┴────────┴───────┴────────┴────────┘
│
┌─────────────────────┘
▼
┌ List ───┐
│┌ ─ ─ ─ ┐│
│ mean │
│├ ─ ─ ─ ┼│─ ─ Centroid 1
│ weight │
│└ ─ ─ ─ ┘│
│ │
│┌ ─ ─ ─ ┐│
│ mean │
│├ ─ ─ ─ ┼│─ ─ Centroid 2
│ weight │
│└ ─ ─ ─ ┘│
│ │
...The TDigest::from_scalar_state() method reverses this processes,
consuming the output of this method and returning an unpacked
TDigest.
Sourcepub fn from_scalar_state(state: &[ScalarValue]) -> Self
pub fn from_scalar_state(state: &[ScalarValue]) -> Self
Unpack the serialized state of a TDigest produced by
Self::to_scalar_state().
§Correctness
Providing input to this method that was not obtained from
Self::to_scalar_state() results in undefined behaviour and may
panic.
Sourcepub fn try_from_parts(
max_size: usize,
sum: f64,
count: f64,
max: f64,
min: f64,
centroids: Vec<Centroid>,
) -> Result<Self, DataFusionError>
pub fn try_from_parts( max_size: usize, sum: f64, count: f64, max: f64, min: f64, centroids: Vec<Centroid>, ) -> Result<Self, DataFusionError>
Construct a TDigest directly from its constituent parts, validating
the inputs.
Together with the Self::centroids(), Self::sum(),
Self::max_size(), Self::count(), Self::max(), and
Self::min() accessors, this allows a digest to be serialized into and
restored from a caller’s own format without round-tripping through a
ScalarValue list (the non-Arrow counterpart to
Self::from_scalar_state()).
Unlike Self::from_scalar_state(), this validates its inputs, returning
an error rather than a silently wrong digest when handed corrupt state.
Callers who trust their data can unwrap().
§Errors
Returns an error if:
minandmaxare both finite butmax < min;- the
centroidsare not sorted in non-decreasing order by mean (the order produced bySelf::centroids()); or - any centroid weight is not finite and strictly positive
(
Self::estimate_quantile()divides by a centroid’s weight, so a zero, negative, or non-finite weight yields silently wrong results).
Trait Implementations§
impl StructuralPartialEq for TDigest
Auto Trait Implementations§
impl Freeze for TDigest
impl RefUnwindSafe for TDigest
impl Send for TDigest
impl Sync for TDigest
impl Unpin for TDigest
impl UnsafeUnpin for TDigest
impl UnwindSafe for TDigest
Blanket Implementations§
impl<T> Allocation for T
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more