Iterstats

Trait Iterstats 

Source
pub trait Iterstats<A>: Iterator {
    // Provided methods
    fn mean(self) -> <A as Mean>::Output
       where Self: Sized + Iterator<Item = A> + Clone,
             A: Mean { ... }
    fn variance(self) -> <A as Variance>::Output
       where Self: Sized + Iterator<Item = A>,
             A: Variance { ... }
    fn stddev(self) -> <A as StdDev>::Output
       where Self: Sized + Iterator<Item = A>,
             A: StdDev { ... }
    fn zscore(self) -> ZScoreIter<<A as ZScore>::Output> 
       where Self: Sized + Iterator<Item = A> + Clone,
             A: ZScore { ... }
    fn normalize(
        self,
        min: <A as Normalize>::Output,
        max: <A as Normalize>::Output,
    ) -> NormalizeIter<<A as Normalize>::Output> 
       where Self: Sized + Iterator<Item = A> + Clone,
             A: Normalize { ... }
    fn sum_of_squares(self) -> <A as SumOfSquares>::Output
       where Self: Sized + Iterator<Item = A>,
             A: SumOfSquares { ... }
    fn median(self) -> <A as Median>::Output
       where Self: Sized + Iterator<Item = A>,
             A: Median { ... }
    fn range(self) -> Option<(<A as Range>::Output, <A as Range>::Output)>
       where Self: Sized + Iterator<Item = A>,
             A: Range { ... }
    fn fill_nan(
        self,
        repl: <A as FillNan>::Output,
    ) -> FillNanIter<impl Iterator<Item = <A as FillNan>::Output>, <A as FillNan>::Output> 
       where Self: Sized + Iterator<Item = A>,
             A: FillNan { ... }
    fn argsort(self) -> ArgSortIter<<A as ArgSort>::Output> 
       where Self: Sized + Iterator<Item = A>,
             A: ArgSort { ... }
    fn rank(self) -> RankIter 
       where Self: Sized + Iterator<Item = A>,
             A: Rank { ... }
}
Expand description

This trait allows you to call all the iterstats calculations as iterator methods.

§Example

use iterstats::Iterstats;

let data = [1f32, 2., 3., 4.];
let mean = data.iter().mean();
assert_eq!(mean, 2.5);
let variance = data.iter().variance();
assert_eq!(variance, 1.25);
let stddev = data.iter().stddev();
assert_eq!(stddev, 1.25f32.sqrt());
let zscores = data.iter().zscore().collect::<Vec<_>>();
assert_eq!(zscores, vec![-1.3416407, -0.4472136, 0.4472136, 1.3416407]);

Provided Methods§

Source

fn mean(self) -> <A as Mean>::Output
where Self: Sized + Iterator<Item = A> + Clone, A: Mean,

Calculate the mean of the collection.

Source

fn variance(self) -> <A as Variance>::Output
where Self: Sized + Iterator<Item = A>, A: Variance,

Calculate the variance of the collection.

Source

fn stddev(self) -> <A as StdDev>::Output
where Self: Sized + Iterator<Item = A>, A: StdDev,

Calculate the population standard deviation of the collection.

Source

fn zscore(self) -> ZScoreIter<<A as ZScore>::Output>
where Self: Sized + Iterator<Item = A> + Clone, A: ZScore,

Calculate the Z-score of each item of the collection.

Source

fn normalize( self, min: <A as Normalize>::Output, max: <A as Normalize>::Output, ) -> NormalizeIter<<A as Normalize>::Output>
where Self: Sized + Iterator<Item = A> + Clone, A: Normalize,

Normalize each item of the collection to a specified range.

use iterstats::Iterstats;

let data = [-1.0f64, -2., 3., 8.];
let norm = data.iter().normalize(0., 100.).collect::<Vec<_>>();
assert_eq!(vec![10., 0., 50., 100.], norm);
Source

fn sum_of_squares(self) -> <A as SumOfSquares>::Output
where Self: Sized + Iterator<Item = A>, A: SumOfSquares,

Calculate the total sum of squares of the collection.

Source

fn median(self) -> <A as Median>::Output
where Self: Sized + Iterator<Item = A>, A: Median,

Calculate the median of the collection.

For integer types this may be inexact if there are an even number of elements and the true median is a non-integer number.

Source

fn range(self) -> Option<(<A as Range>::Output, <A as Range>::Output)>
where Self: Sized + Iterator<Item = A>, A: Range,

Calculate the range of the collection.

This gets the minimum & maximum in 1 pass. Returned is a tuple of Some((min, max)), unless the iterator is empty, in which case None is returned.

Source

fn fill_nan( self, repl: <A as FillNan>::Output, ) -> FillNanIter<impl Iterator<Item = <A as FillNan>::Output>, <A as FillNan>::Output>
where Self: Sized + Iterator<Item = A>, A: FillNan,

Replace NANs with another value.

Source

fn argsort(self) -> ArgSortIter<<A as ArgSort>::Output>
where Self: Sized + Iterator<Item = A>, A: ArgSort,

Get the indexes that would produce a sorted iterator.

Source

fn rank(self) -> RankIter
where Self: Sized + Iterator<Item = A>, A: Rank,

Get the rank order of each element in an iterator.

Implementors§

Source§

impl<I, A> Iterstats<A> for I
where I: Iterator + ?Sized,