Struct inc_stats::Percentiles[][src]

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

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

Create a new Percentiles object with no data

Add a data point

Get the number of data points

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);

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);

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

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Creates a value from an iterator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.