- Notifications
You must be signed in to change notification settings - Fork3
🦀 Online statistics in Rust
License
NotificationsYou must be signed in to change notification settings
online-ml/watermill.rs
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
watermill
is crate 🦀 for Blazingly fast, generic and serializable online statistics.
Let's compute the online median and then serialize it:
use watermill::quantile::Quantile;use watermill::stats::Univariate;let data:Vec<f64> =vec![9.,7.,3.,2.,6.,1.,8.,5.,4.];letmut running_median:Quantile<f64> =Quantile::new(0.5_f64).unwrap();for xin data.into_iter(){ running_median.update(x);// update the current statisticsprintln!("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 watermill::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 watermill::rolling::Rolling;use watermill::stats::Univariate;use watermill::variance::Variance;let data:Vec<f64> =vec![9.,7.,3.,2.,6.,1.,8.,5.,4.];letmut running_var:Variance<f64> =Variance::default();// We wrap `running_var` inside the `Rolling` struct.letmut rolling_var:Rolling<f64> =Rolling::new(&mut running_var,2).unwrap();for xin data.into_iter(){ rolling_var.update(x);}assert_eq!(rolling_var.get(),0.5);
Add the following line to yourcargo.toml
:
[dependencies]watermill = "0.1.0"
Statistics | Rollable ? |
---|---|
Mean | ✅ |
Variance | ✅ |
Sum | ✅ |
Min | ✅ |
Max | ✅ |
Count | ❌ |
Quantile | ✅ |
Peak to peak | ✅ |
Exponentially weighted mean | ❌ |
Exponentially weighted variance | ❌ |
Interquartile range | ✅ |
Kurtosis | ❌ |
Skewness | ❌ |
Covariance | ❌ |
Thestats
module of theriver
library inPython
greatly inspired this crate.
About
🦀 Online statistics in Rust
Topics
Resources
License
Stars
Watchers
Forks
Packages0
No packages published