#probability #statistics #stats #distribution #math

statrs

Statistical computing library for Rust

14 releases (breaking)

0.11.0 May 8, 2019
0.10.0 Oct 2, 2018
0.9.0 Nov 9, 2017
0.7.0 May 29, 2017
0.3.2 Nov 19, 2016

#7 in Math

Download history 373/week @ 2019-01-23 534/week @ 2019-01-30 357/week @ 2019-02-06 322/week @ 2019-02-13 609/week @ 2019-02-20 614/week @ 2019-02-27 623/week @ 2019-03-06 674/week @ 2019-03-13 892/week @ 2019-03-20 602/week @ 2019-03-27 542/week @ 2019-04-03 556/week @ 2019-04-10 562/week @ 2019-04-17 740/week @ 2019-04-24 687/week @ 2019-05-01

2,580 downloads per month
Used in 26 crates (12 directly)

MIT license

613KB
11K SLoC

statrs

Build Status Codecov MIT licensed Crates.io

Current Version: v0.11.0

Should work for both nightly and stable Rust.

NOTE: While I will try to maintain backwards compatibility as much as possible, since this is still a 0.x.x project the API is not considered stable and thus subject to possible breaking changes up until v1.0.0

Description

Statrs provides a host of statistical utilities for Rust scientific computing. Included are a number of common distributions that can be sampled (i.e. Normal, Exponential, Student's T, Gamma, Uniform, etc.) plus common statistical functions like the gamma function, beta function, and error function.

This library is a work-in-progress port of the statistical capabilities in the C# Math.NET library. All unit tests in the library borrowed from Math.NET when possible and filled-in when not.

This library is a work-in-progress and not complete. Planned for future releases are continued implementations of distributions as well as porting over more statistical utilities

Please check out the documentation here

Usage

Add the following to your Cargo.toml

[dependencies]
statrs = "0.11.0"

and this to your crate root

extern crate statrs;

Examples

Statrs v0.11.0 comes with a number of commonly used distributions including Normal, Gamma, Student's T, Exponential, Weibull, etc. The common use case is to set up the distributions and sample from them which depends on the Rand crate for random number generation

use rand;
use statrs::distribution::{Exponential, Distribution};

let mut r = rand::StdRng::new().unwrap();
let n = Exponential::new(0.5).unwrap();
print!("{}", n.Sample::<StdRng>(&mut r);

Statrs also comes with a number of useful utility traits for more detailed introspection of distributions

use statrs::distribution::{Exponential, Univariate, Continuous};
use statrs::statistics::{Mean, Variance, Entropy, Skewness};

let n = Exponential::new(1.0).unwrap();
assert_eq!(n.mean(), 1.0);
assert_eq!(n.variance(), 1.0);
assert_eq!(n.entropy(), 1.0);
assert_eq!(n.skewness(), 2.0);
assert_eq!(n.cdf(1.0), 0.6321205588285576784045);
assert_eq!(n.pdf(1.0), 0.3678794411714423215955);

as well as utility functions including erf, gamma, ln_gamma, beta, etc.

For functions or methods with failure modes, Statrs provides a checked and unchecked interface. The unchecked interface will panic on an error while the checked interface returns a Result.

use statrs::statistics::CheckedVariance;
use statrs::distribution::FisherSnedecor;

let n = FisherSnedecor::new(1.0, 1.0).unwrap();
assert!(n.checked_variance().is_err());
// n.variance(); // uncomment this line to see it panic

Contributing

Want to contribute? Check out some of the issues marked help wanted

How to contribute

Clone the repo:

git clone https://github.com/boxtown/statrs

Create a feature branch:

git checkout -b <feature_branch> master

After commiting your code:

git push -u origin <feature_branch>

Then submit a PR, preferably referencing the relevant issue.

Style

This repo makes use of rustfmt with the configuration specified in rustfmt.toml. See https://github.com/rust-lang-nursery/rustfmt for instructions on installation and usage and run the formatter using rustfmt --write-mode overwrite *.rs in the src directory before committing.

Commit messages

Please be explicit and and purposeful with commit messages.

Bad

Modify test code

Good

test: Update statrs::distribution::Normal test_cdf

Dependencies

~1MB