This crate provides estimators for statistics on a sequence of numbers. Thetypical workflow looks like this:
concatenate
ordefine_moments
.new()
.add()
orcollect()
.mean()
or similar.You can run several estimators in parallel and merge them into one withmerge()
.
Everything is calculated iteratively in a single pass using constant memory,so the sequence of numbers can be an iterator. The used algorithms try toavoid numerical instabilities.
If you wantSerde support,include"serde1"
in your list of features.
Note that deserializing does not currently check for all invalid inputs.For example, if you deserialize a corruptedVariance
it may returna negative value for variance, even though that is mathematically impossible.In a future minor release some of these checks may be added.
useaverage::{MeanWithError,Estimate};letmuta:MeanWithError= (1..6).map(f64::from).collect();a.add(42.);println!("The mean is {} ± {}.",a.mean(),a.error());
Mean
) and its error (MeanWithError
).WeightedMean
) and its error(WeightedMeanWithError
).Variance
), skewness (Skewness
) and kurtosis(Kurtosis
).define_moments
).Quantile
).Min
) and maximum (Max
).The estimators are designed to have minimal state. The recommended way tocalculate several of them at once is to create a struct with all theestimators you need. You can then implementadd
for your struct byforwarding to the underlying estimators. Everything is inlined, so thereshould be no overhead.
You can avoid the boilerplate code by using theconcatenate
macro.
Note that calculating moments requires calculating the lower moments, so youonly need to include the highest moment in your struct.
Thedefine_histogram
macro can be used to define a histogram struct thatuses constant memory. SeeHistogram10
(defined usingdefine_histogram!(..., 10)
) and the extension traitHistogram
for the methods available to the generated struct.
assert_almost_eq | Assert that two numbers are almost equal to each other. |
concatenate | Concatenate several iterative estimators into one. |
define_histogram | Define a histogram with a number of bins known at compile time. |
define_moments | Define an estimator of all moments up to a number given at compile time. |
impl_from_iterator | Implement |
Histogram10 | A histogram with a number of bins known at compile time. |
Kurtosis | Estimate the arithmetic mean, the variance, the skewness and the kurtosis ofa sequence of numbers ("population"). |
Max | Estimate the maximum of a sequence of numbers ("population"). |
Mean | Estimate the arithmetic mean of a sequence of numbers ("population"). |
Min | Estimate the minimum of a sequence of numbers ("population"). |
Moments4 | Estimate the first N moments of a sequence of numbers ("population"). |
Quantile | Estimate the p-quantile of a sequence of numbers ("population"). |
Skewness | Estimate the arithmetic mean, the variance and the skewness of a sequence ofnumbers ("population"). |
Variance | Estimate the arithmetic mean and the variance of a sequence of numbers("population"). |
WeightedMean | Estimate the weighted and unweighted arithmetic mean of a sequence ofnumbers ("population"). |
WeightedMeanWithError | Estimate the weighted and unweighted arithmetic mean and the unweightedvariance of a sequence of numbers ("population"). |
Estimate | Estimate a statistic of a sequence of numbers ("population"). |
Histogram | Get the bins and ranges from a histogram. |
Merge | Merge another sample into this one. |
MeanWithError | Alias for |
Prefix searches with a type followed by a colon (e.g.,fn:
) to restrict the search to a given type.
Accepted types are:fn
,mod
,struct
,enum
,trait
,type
,macro
, andconst
.
Search functions by type signature (e.g.,vec -> usize
or* -> vec
)
Search multiple things at once by splitting your query with comma (e.g.,str,u8
orString,struct:Vec,test
)