Online statistics in Rust 🦀

online-statistics is crate 🦀 for Blazingly fast, generic and serializable online statistics.

## Quickstart

Let's compute the online median and then serialize it: ```rust use onlinestatistics::quantile::Quantile; use onlinestatistics::stats::Univariate; let data: Vec = vec![9., 7., 3., 2., 6., 1., 8., 5., 4.]; let mut runningmedian: Quantile = Quantile::new(0.5f64).unwrap(); for x in data.intoiter() { runningmedian.update(x); // update the current statistics println!("The actual median value is: {}", runningmedian.get()); } asserteq!(running_median.get(), 5.0);

// Convert the statistic to a JSON string. let serialized = serdejson::tostring(&running_median).unwrap();

// Convert the JSON string back to a statistic. let deserialized: Quantile = serdejson::fromstr(&serialized).unwrap();

Now let's compute the online sum using the iterators: rust use onlinestatistics::iter::IterStatisticsExtend; let data: Vec = vec![1., 2., 3.]; let vectrue: Vec = vec![1., 3., 6.]; for (d, t) in data.intoiter().onlinesum().zip(vectrue.intoiter()) { assert_eq!(d, t); // ^^^^^^^^^^ } ```

You can also compute rolling statistics; in the following example let's compute the rolling sum on 2 previous data: ```rust

use onlinestatistics::rolling::Rolling; use onlinestatistics::stats::Univariate; use onlinestatistics::variance::Variance; let data: Vec = vec![9., 7., 3., 2., 6., 1., 8., 5., 4.]; let mut runningvar: Variance = Variance::default(); // We wrap running_var inside the Rolling struct. let mut rollingvar: Rolling = Rolling::new(&mut runningvar, 2).unwrap(); for x in data.intoiter() { rollingvar.update(x); } asserteq!(rollingvar.get(), 0.5); ```

## Installation

Add the following line to your cargo.toml: [dependencies] online-statistics = "0.2.1"

Statistics available

| Statistics | Rollable ?| |--------------------------------- |---------- | | Mean | ✅ | | Variance | ✅ | | Sum | ✅ | | Min | ✅ | | Max | ✅ | | Count | ❌ | | Quantile | ✅ | | Peak to peak | ✅ | | Exponentially weighted mean | ❌ | | Exponentially weighted variance | ❌ | | Interquartile range | ✅ | | Kurtosis | ❌ | | Skewness | ❌ | | Covariance | ❌ |

## Inspiration

The stats module of the river library in Python greatly inspired this crate.