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
pub fn percentiles<P, I>(
&self,
percentiles: I
) -> Result<Option<Vec<T>>, StatsError> where
P: DerefCopy<Output = f64>,
I: IntoIterator<Item = P>,
pub fn percentiles<P, I>(
&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>
pub fn percentile(
&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);