SummStats

Struct SummStats 

Source
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>

Source

pub fn new() -> Self

Create a new SummStats struct with no data

Source

pub fn add(&mut self, bval: impl DerefCopy<Output = T>)

Add a number

§Examples
let mut stats = inc_stats::SummStats::new();
stats.add(0.0);
stats.add(&1.2);
assert_eq!(2, stats.count());
§Panics

when the internal count can’t be converted into the float data type.

Source

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

pub fn count(&self) -> u64

Get the number of values added

Source

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

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

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

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

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

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

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: Debug + Float + FromPrimitive + AddAssign> Debug for SummStats<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Float + FromPrimitive + AddAssign> Default for SummStats<T>

Source§

fn default() -> Self

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

impl<T: Float + FromPrimitive + AddAssign, V: DerefCopy<Output = T>> FromIterator<V> for SummStats<T>

Source§

fn from_iter<I>(iter: I) -> Self
where 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.