Online-statistics is crate πŸ¦€ for Blazingly fast, generic and serializable online statistics

Overview

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:

= serde_json::from_str(&serialized).unwrap(); ">
use online_statistics::quantile::Quantile;
use online_statistics::stats::Univariate;
let data: Vec<f64> = vec![9., 7., 3., 2., 6., 1., 8., 5., 4.];
let mut running_median: Quantile<f64> = Quantile::new(0.5_f64).unwrap();
for x in data.into_iter() {
    running_median.update(x); // update the current statistics
    println!("The actual median value is: {}", running_median.get());
}
assert_eq!(running_median.get(), 5.0);

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

// Convert the JSON string back to a statistic.
let deserialized: Quantile<f64> = serde_json::from_str(&serialized).unwrap();

Now let's compute the online sum using the iterators:

use online_statistics::iter::IterStatisticsExtend;
let data: Vec<f64> = vec![1., 2., 3.];
let vec_true: Vec<f64> = vec![1., 3., 6.];
for (d, t) in data.into_iter().online_sum().zip(vec_true.into_iter()) {
    assert_eq!(d, t); //       ^^^^^^^^^^
}

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

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

Installation


Add the following line to your cargo.toml:

[dependencies]
online-statistics = "0.1.0"

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.

You might also like...
Rust crate which provides direct access to files within a Debian archive

debarchive This Rust crate provides direct access to files within a Debian archive. This crate is used by our debrep utility to generate the Packages

A fancy diagnostics & error reporting crate
A fancy diagnostics & error reporting crate

A fancy diagnostics & error reporting crate

Debug2 is a pretty printing crate based on std::fmt

debug2 is a pretty printing crate based on std::fmt Why not just use Debug The Debug trait is good, but the problem is it is not very good at n

Granular locking crate for Rust

Granular locking crate for Rust. Instead of using coarse-grained Mutex or RwLock which can be used to lock an entire structure, glock provides more granular locking.

A crate to implement leader election for Kubernetes workloads in Rust.

Kubernetes Leader Election in Rust This library provides simple leader election for Kubernetes workloads.

Tiny Rust crate to iterate bit combinations

bit_combi_iter bit_combi_iter is a small dependency-free crate to enumerate all bit combinations less than given unsigned integer value keeping 1s in

Rust crate for reading SER files used in astrophotography

Rust crate for reading SER files used in astrophotography.

A Rust crate for handling URNs.

URN A Rust crate for handling URNs. Parsing and comparison is done according to the spec (meaning only part of the URN is used for equality checks). S

Crate of GitHub’s collection of gitignores, embedded, automatically updated

Gitignores GitHub’s collection of gitignores, embedded, automatically updated. API documentation. Public Domain via CC0-1.0 (same as source data). MSR

Owner
Adil Zouitine
I try to make reinforcement learning boring.
Adil Zouitine
Output the individual word-count statistics from a set of files

Output the individual word-count statistics from a set of files, or generate a curated word list

Johnny Tidemand Vestergaard 1 Apr 3, 2022
archive-rs provides a generic way of dealing with multiple archive and compression formats in Rust

archive-rs A Rust crate that aims to provide a generic way of dealing with multiple archive and compression formats by providing a generic abstraction

S.J.R. van Schaik 2 Nov 21, 2021
Render cargo dependency tree in online

Cargo Tree Online Check out rendered page Render cargo dependency tree in online. Usage trunk serve Copy and paste the content of Cargo.lock file to

Kangwook Lee (μ΄κ°•μš±) 2 Sep 23, 2021
β¬’ hexil.org: The libre online alternative to Settlers of Catan

Hexer Getting started for developers Backend Install Rust and Cargo, for example using rustup. Navigate to the back directory. Then start the backend:

Hexil 4 Sep 5, 2022
Membrane is an opinionated crate that generates a Dart package from a Rust library. Extremely fast performance with strict typing and zero copy returns over the FFI boundary via bincode.

Membrane is an opinionated crate that generates a Dart package from a Rust library. Extremely fast performance with strict typing and zero copy returns over the FFI boundary via bincode.

Jerel Unruh 70 Dec 13, 2022
microtemplate - A fast, microscopic helper crate for runtime string interpolation.

microtemplate A fast, microscopic helper crate for runtime string interpolation. Design Goals Very lightweight: I want microtemplate to do exactly one

_iPhoenix_ 13 Jan 31, 2022
This crate allows writing a struct in Rust and have it derive a struct of arrays layed out in memory according to the arrow format.

Arrow2-derive - derive for Arrow2 This crate allows writing a struct in Rust and have it derive a struct of arrays layed out in memory according to th

Jorge Leitao 29 Dec 27, 2022
This crate bridges between gstreamer and tracing ecosystems.

This crate provides a bridge between gstreamer and the tracing ecosystem. The goal is to allow Rust applications utilizing GStreamer to better integra

Standard Cognition OSS 17 Jun 7, 2022
The efficient and elegant crate to count variants of Rust's Enum.

variant-counter The efficient and elegant crate to count variants of Rust's Enum. Get started #[derive(VariantCount)] #[derive(VariantCount)] pub enum

Folyd 16 Sep 29, 2022
A Rust crate that provides a simple interface for LZMA compression and decompression.

rust-lzma Documentation This crate provides a simple interface to liblzma. LZMA is more commonly known as XZ or 7zip, (as in, files with the .xz or .7

null 52 Nov 26, 2022