Struct inc_stats::Percentiles [−][src]
Data percentile struct
This struct stores data to allow efficient computation of percentiles. This struct takes linear space. It implements FromIterator to allow collection. This collection ignores NaNs.
The structure is designed for efficient computation of percentiles when data is added and then percentiles are computed. Adding data is constant time, querying percentiles is linear time, with some caching to make it faster for computing several percentiles. If you were going to query percentiles while adding data, then you probably want to use a different data structure.
Examples
let mut percs = inc_stats::Percentiles::new(); for &num in &[2.0, 4.0, 8.0] { percs.add(num); } assert_eq!(3, percs.count());
let percs: inc_stats::Percentiles<f64> = [2.0, 4.0, 8.0].iter().collect(); assert_eq!(3, percs.count());
Implementations
impl<T: Float + FromPrimitive> Percentiles<T>[src]
pub fn new() -> Self[src]
Create a new Percentiles object with no data
pub fn add(&mut self, rval: impl DerefCopy<Output = T>)[src]
Add a data point
pub fn count(&self) -> usize[src]
Get the number of data points
pub fn percentiles<P, I>(
&self,
percentiles: I
) -> Result<Option<Vec<T>>, StatsError> where
P: DerefCopy<Output = f64>,
I: IntoIterator<Item = P>, [src]
&self,
percentiles: I
) -> Result<Option<Vec<T>>, StatsError> where
P: DerefCopy<Output = f64>,
I: IntoIterator<Item = P>,
Get a number of percentiles
This takes linear time in the number of added data points, and log linear in the number of percentiles. This will be marginally more efficient than calling percentile repeatedly in a bad order.
Examples:
let percs: inc_stats::Percentiles<f64> = [1.0, 3.0, 7.0].iter().collect(); let quarts = percs.percentiles(&[0.75, 0.25, 0.5]).unwrap().unwrap(); assert!((5.0 - quarts[0]).abs() < 1.0e-6); assert!((2.0 - quarts[1]).abs() < 1.0e-6); assert!((3.0 - quarts[2]).abs() < 1.0e-6);
pub fn percentile(
&self,
percentile: impl DerefCopy<Output = f64>
) -> Result<Option<T>, StatsError>[src]
&self,
percentile: impl DerefCopy<Output = f64>
) -> Result<Option<T>, StatsError>
Get a percentile
Linear time.
Examples:
let percs: inc_stats::Percentiles<f64> = [1.0, 5.0].iter().collect(); let quart = percs.percentile(0.25).unwrap().unwrap(); assert!((2.0 - quart).abs() < 1.0e-6);
pub fn median(&self) -> Option<T>[src]
Get the median
Linear time.
Examples:
let percs: inc_stats::Percentiles<f64> = [1.0, 5.0, 100.0].iter().collect(); let med = percs.median().unwrap(); assert_eq!(5.0, med);
Trait Implementations
impl<T: Debug + Float + FromPrimitive> Debug for Percentiles<T>[src]
impl<T: Float + FromPrimitive> Default for Percentiles<T>[src]
impl<T: Float + FromPrimitive, V: DerefCopy<Output = T>> FromIterator<V> for Percentiles<T>[src]
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = V>, [src]
I: IntoIterator<Item = V>,
Auto Trait Implementations
impl<T> !RefUnwindSafe for Percentiles<T>
impl<T> Send for Percentiles<T> where
T: Send,
T: Send,
impl<T> !Sync for Percentiles<T>
impl<T> Unpin for Percentiles<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Percentiles<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,