Skip to main content

Quantile

Struct Quantile 

Source
pub struct Quantile<Num, NumArr, UsizeArr>
where Num: Float,
{ /* private fields */ }
Available on crate features libm or std only.
Expand description

Moving quantile over a sliding window based on partitioning heaps.

Implementations§

Source§

impl<Num> Quantile<Num, Vec<Num>, Vec<usize>>

Source

pub fn new(probability: Num, window_size: usize) -> Self

Available on crate features alloc or std only.

Create a new quantile tracker with a specific window size.

§Arguments
  • probability – Probability of the quantile to compute. For example, 0.5 for the median, or 0.75 for the 75th percentile.
  • window_size – Sliding window size. The target quantile is tracked for this many most recent observations. The algorithm is intended for moderate window sizes of roughly 10 to 10,000 elements.
§Panics
  • when window_size is zero
  • when probability is outside 0..=1
Source§

impl<Num, const WIN_SIZE: usize> Quantile<Num, [Num; WIN_SIZE], [usize; WIN_SIZE]>

Source

pub fn new(probability: Num) -> Self

Create a new quantile tracker with a specific window size.

§Arguments
  • window_size – Sliding window size. The target quantile is tracked for this many most recent observations. The algorithm is intended for moderate window sizes of roughly 10 to 10,000 elements.
  • probability – Probability of the quantile to compute. For example, 0.5 for the median, or 0.75 for the 75th percentile.
§Panics
  • when window_size is zero
  • when probability is outside 0..=1
Source§

impl<Num, NumArr, UsizeArr> Quantile<Num, NumArr, UsizeArr>
where Num: Float + FromPrimitive + ToPrimitive, NumArr: Index<usize, Output = Num> + IndexMut<usize, Output = Num>, UsizeArr: Index<usize, Output = usize> + IndexMut<usize, Output = usize>,

Source

pub fn add(&mut self, value: Num)

Add an observation and update the quantile estimate.

If the window is full, the oldest observation will be removed.

§Arguments
  • value – the next observation in your data stream
Source

pub fn get(&self) -> Num

The target quantile for the last n ≤ window_size observations.

For example, when initialized with probability = 0.2, this returns a value ≥ 20% of the observations in the sliding window, and ≤ 80% of them.

This returns NAN if zero values have been observed so far.

Auto Trait Implementations§

§

impl<Num, NumArr, UsizeArr> Freeze for Quantile<Num, NumArr, UsizeArr>
where Num: Freeze, NumArr: Freeze, UsizeArr: Freeze,

§

impl<Num, NumArr, UsizeArr> RefUnwindSafe for Quantile<Num, NumArr, UsizeArr>
where Num: RefUnwindSafe, NumArr: RefUnwindSafe, UsizeArr: RefUnwindSafe,

§

impl<Num, NumArr, UsizeArr> Send for Quantile<Num, NumArr, UsizeArr>
where Num: Send, NumArr: Send, UsizeArr: Send,

§

impl<Num, NumArr, UsizeArr> Sync for Quantile<Num, NumArr, UsizeArr>
where Num: Sync, NumArr: Sync, UsizeArr: Sync,

§

impl<Num, NumArr, UsizeArr> Unpin for Quantile<Num, NumArr, UsizeArr>
where Num: Unpin, NumArr: Unpin, UsizeArr: Unpin,

§

impl<Num, NumArr, UsizeArr> UnsafeUnpin for Quantile<Num, NumArr, UsizeArr>
where Num: UnsafeUnpin, NumArr: UnsafeUnpin, UsizeArr: UnsafeUnpin,

§

impl<Num, NumArr, UsizeArr> UnwindSafe for Quantile<Num, NumArr, UsizeArr>
where Num: UnwindSafe, NumArr: UnwindSafe, UsizeArr: UnwindSafe,

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> 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, 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.