Struct inc_stats::Percentiles[][src]

pub struct Percentiles<T: Float + FromPrimitive = f64> { /* fields omitted */ }

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.

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 = [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]

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 = [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]

Get a percentile

Linear time.

Examples:

let percs: inc_stats::Percentiles = [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 = [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]

Auto Trait Implementations

impl<T = f64> !RefUnwindSafe for Percentiles<T>

impl<T> Send for Percentiles<T> where
    T: Send

impl<T = f64> !Sync for Percentiles<T>

impl<T> Unpin for Percentiles<T> where
    T: Unpin

impl<T> UnwindSafe for Percentiles<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.