pub struct SummStats<T: Float + FromPrimitive + AddAssign> { /* private fields */ }Expand description
Summary statistics struct
This struct aggregates data to compute summary statistics using constant space overhead. It implements the FromIterator trait so it can be collected from an iterator of floats.
§Examples
let mut stats = inc_stats::SummStats::new();
for &num in &[2.0, 4.0, 8.0] {
stats.add(num);
}
assert_eq!(3, stats.count());let stats: inc_stats::SummStats<f64> = [2.0, 4.0, 8.0].iter().collect();
assert_eq!(3, stats.count());Implementations§
Source§impl<T: Float + FromPrimitive + AddAssign> SummStats<T>
impl<T: Float + FromPrimitive + AddAssign> SummStats<T>
Sourcepub fn checked_add(
&mut self,
rval: impl DerefCopy<Output = T>,
) -> Result<(), StatsError>
pub fn checked_add( &mut self, rval: impl DerefCopy<Output = T>, ) -> Result<(), StatsError>
Add a number
Check for conversion errors, will only happen when the internal count can’t be converted into the float data type.
§Examples
let mut stats = inc_stats::SummStats::new();
stats.checked_add(0.0).unwrap();
assert_eq!(1, stats.count());Sourcepub fn min(&self) -> Option<T>
pub fn min(&self) -> Option<T>
Get the minimum non nan value
Constant time. If no non nan values have been added, this is None.
§Examples
let stats: inc_stats::SummStats<_> = [2.0, 4.0, std::f64::NAN].iter().collect();
assert_eq!(2.0, stats.min().unwrap());let mut stats = inc_stats::SummStats::new();
stats.add(std::f64::NAN);
assert!(stats.min().is_none());Sourcepub fn max(&self) -> Option<T>
pub fn max(&self) -> Option<T>
Get the maximum non nan value
Constant time. If no non nan values have been added, this is None.
§Examples
let stats: inc_stats::SummStats<_> = [2.0, 4.0, std::f64::NAN].iter().collect();
assert_eq!(4.0, stats.max().unwrap());Sourcepub fn mean(&self) -> Option<T>
pub fn mean(&self) -> Option<T>
Get the mean
Constant time.
§Examples
let stats: inc_stats::SummStats<f64> = [2.0, 4.0].iter().collect();
assert!((3.0 - stats.mean().unwrap()).abs() < 1.0e-6);let stats = inc_stats::SummStats::<f64>::new();
assert!(stats.mean().is_none());Sourcepub fn sum(&self) -> T
pub fn sum(&self) -> T
Get the sum
Constant time.
§Examples
let stats: inc_stats::SummStats<f64> = [2.0, 4.0].iter().collect();
assert!((6.0 - stats.sum()).abs() < 1.0e-6);Sourcepub fn standard_deviation(&self) -> Option<T>
pub fn standard_deviation(&self) -> Option<T>
Get the sample standard deviation
Constant time.
§Examples
let stats: inc_stats::SummStats<f64> = [2.0, 4.0].iter().collect();
assert!((1.4142136 - stats.standard_deviation().unwrap()).abs() < 1.0e-6);Sourcepub fn variance(&self) -> Option<T>
pub fn variance(&self) -> Option<T>
Get the sample variance
Constant time.
§Examples
let stats: inc_stats::SummStats<f64> = [2.0, 4.0].iter().collect();
assert!((2.0 - stats.variance().unwrap()).abs() < 1.0e-6);let mut stats = inc_stats::SummStats::new();
stats.add(0.0);
assert!(stats.variance().is_none());Sourcepub fn standard_error(&self) -> Option<T>
pub fn standard_error(&self) -> Option<T>
Get the standard error
Constant time.
§Examples
let stats: inc_stats::SummStats<f64> = [2.0, 4.0].iter().collect();
assert!((1.0 - stats.standard_error().unwrap()).abs() < 1.0e-6);Trait Implementations§
Source§impl<T: Float + FromPrimitive + AddAssign, V: DerefCopy<Output = T>> FromIterator<V> for SummStats<T>
impl<T: Float + FromPrimitive + AddAssign, V: DerefCopy<Output = T>> FromIterator<V> for SummStats<T>
Source§fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = V>,
fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = V>,
Creates a value from an iterator. Read more
Auto Trait Implementations§
impl<T> Freeze for SummStats<T>where
T: Freeze,
impl<T> RefUnwindSafe for SummStats<T>where
T: RefUnwindSafe,
impl<T> Send for SummStats<T>where
T: Send,
impl<T> Sync for SummStats<T>where
T: Sync,
impl<T> Unpin for SummStats<T>where
T: Unpin,
impl<T> UnwindSafe for SummStats<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more