Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
Unreleased


v0.16.0

- Adds an `sf` method to the `ContinuousCDF` and `DiscreteCDF` traits
- Calculates the survival function (CDF complement) for the distribution.
- Survival function implemented for all distributions implementing `ContinuousCDF` and `DiscreteCDF`
- See [PR description](https://github.com/statrs-dev/statrs/pull/172) for in-depth changes
- update `nalgebra` to `0.29`

v0.15.0

Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ description = "Statistical computing library for Rust"
license = "MIT"
keywords = ["probability", "statistics", "stats", "distribution", "math"]
categories = ["science"]
documentation = "https://docs.rs/statrs/0.15.0/statrs/"
homepage = "https://github.com/statrs-dev/statrs"
repository = "https://github.com/statrs-dev/statrs"
edition = "2018"
Expand Down
220 changes: 96 additions & 124 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,124 +1,96 @@
# statrs

[![Build Status](https://travis-ci.org/boxtown/statrs.svg?branch=master)](https://travis-ci.org/boxtown/statrs)
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE.md)
[![Crates.io](https://img.shields.io/crates/v/statrs.svg)](https://crates.io/crates/statrs)

## Current Version: v0.16.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](https://docs.rs/statrs/*/statrs/)

## Usage

Add the most recent release to your `Cargo.toml`

```Rust
[dependencies]
statrs = "0.16"
```

## Examples

Statrs 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

```Rust
use statrs::distribution::Exp;
use rand::distributions::Distribution;

let mut r = rand::rngs::OsRng;
let n = Exp::new(0.5).unwrap();
print!("{}", n.sample(&mut r));
```

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

```Rust
use statrs::distribution::{Exp, Continuous, ContinuousCDF};
use statrs::statistics::Distribution;

let n = Exp::new(1.0).unwrap();
assert_eq!(n.mean(), Some(1.0));
assert_eq!(n.variance(), Some(1.0));
assert_eq!(n.entropy(), Some(1.0));
assert_eq!(n.skewness(), Some(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.

```Rust
use statrs::statistics::Distribution;
use statrs::distribution::FisherSnedecor;

let n = FisherSnedecor::new(1.0, 1.0).unwrap();
assert!(n.variance().is_none());
```

## Contributing

Want to contribute? Check out some of the issues marked [help wanted](https://github.com/statrs-dev/statrs/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22)

### How to contribute

Clone the repo:

```
git clone https://github.com/statrs-dev/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
```
# statrs

![tests](https://github.com/statrs-dev/statrs/actions/workflows/test.yml/badge.svg)
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE.md)]
[![Crate](https://img.shields.io/crates/v/statrs.svg)](https://crates.io/crates/statrs)
![docs.rs](https://img.shields.io/docsrs/statrs?style=for-the-badge).
[![codecov](https://codecov.io/gh/statrs-dev/statrs/graph/badge.svg?token=XtMSMYXvIf)](https://codecov.io/gh/statrs-dev/statrs)

## Current Version: v0.16.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](https://docs.rs/statrs/*/statrs/).

## Usage

Add the most recent release to your `Cargo.toml`

```Rust
[dependencies]
statrs = "0.16"
```

For examples, view the docs hosted on ![docs.rs](https://img.shields.io/docsrs/statrs?style=for-the-badge).

## Contributing

Want to contribute?
Check out some of the issues marked [help wanted](https://github.com/statrs-dev/statrs/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22)

### How to contribute

Clone the repo:

```
git clone https://github.com/statrs-dev/statrs
```

Create a feature branch:

```
git checkout -b <feature_branch> master
```

Write your code and docs, then ensure it is formatted:

The below sample modify in-place, use `--check` flag to view diff without making file changes.
Not using `fmt` from +nightly may result in some warnings and different formatting.
Our CI will `fmt`, but less chores in commit history are appreciated.

```
cargo +nightly fmt
```

After commiting your code:

```
git push -u origin <feature_branch>
```

Then submit a PR, preferably referencing the relevant issue, if it exists.

### Commit messages

Please be explicit and and purposeful with commit messages.
[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) encouraged.

#### Bad

```
Modify test code
```

#### Good

```
test: Update statrs::distribution::Normal test_cdf
```

### Communication Expectations

Please allow at least one week before pinging issues/pr's.

37 changes: 33 additions & 4 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
# Run using `rustfmt --write-mode overwrite *.rs` in the
# root of the src directory. You may still get some
# formatting errors (whitespace etc) which should be
# fixed manually before committing.
# This rustfmt file is added for configuration, but in practice much of our
# code is hand-formatted, frequently with more readable results.
# taken from rust-random/rand

# Comments:
normalize_comments = true
wrap_comments = false
comment_width = 90 # small excess is okay but prefer 80

# Arguments:
use_small_heuristics = "Default"
# TODO: single line functions only where short, please?
# https://github.com/rust-lang/rustfmt/issues/3358
fn_single_line = false
fn_params_layout = "Compressed"
overflow_delimited_expr = true
where_single_line = true

# enum_discrim_align_threshold = 20
# struct_field_align_threshold = 20

# Compatibility:
edition = "2021"

# Misc:
inline_attribute_width = 80
blank_lines_upper_bound = 2
reorder_impl_items = true
# report_todo = "Unnumbered"
# report_fixme = "Unnumbered"

# Ignored files:
ignore = []
24 changes: 12 additions & 12 deletions src/distribution/bernoulli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl DiscreteCDF<u64, f64> for Bernoulli {
///
/// # Formula
///
/// ```ignore
/// ```text
/// if x < 0 { 0 }
/// else if x >= 1 { 1 }
/// else { 1 - p }
Expand All @@ -106,7 +106,7 @@ impl DiscreteCDF<u64, f64> for Bernoulli {
///
/// # Formula
///
/// ```ignore
/// ```text
/// if x < 0 { 1 }
/// else if x >= 1 { 0 }
/// else { p }
Expand All @@ -123,7 +123,7 @@ impl Min<u64> for Bernoulli {
///
/// # Formula
///
/// ```ignore
/// ```text
/// 0
/// ```
fn min(&self) -> u64 {
Expand All @@ -138,7 +138,7 @@ impl Max<u64> for Bernoulli {
///
/// # Formula
///
/// ```ignore
/// ```text
/// 1
/// ```
fn max(&self) -> u64 {
Expand All @@ -152,7 +152,7 @@ impl Distribution<f64> for Bernoulli {
///
/// # Formula
///
/// ```ignore
/// ```text
/// p
/// ```
fn mean(&self) -> Option<f64> {
Expand All @@ -163,7 +163,7 @@ impl Distribution<f64> for Bernoulli {
///
/// # Formula
///
/// ```ignore
/// ```text
/// p * (1 - p)
/// ```
fn variance(&self) -> Option<f64> {
Expand All @@ -174,7 +174,7 @@ impl Distribution<f64> for Bernoulli {
///
/// # Formula
///
/// ```ignore
/// ```text
/// q = (1 - p)
/// -q * ln(q) - p * ln(p)
/// ```
Expand All @@ -186,7 +186,7 @@ impl Distribution<f64> for Bernoulli {
///
/// # Formula
///
/// ```ignore
/// ```text
/// q = (1 - p)
/// (1 - 2p) / sqrt(p * q)
/// ```
Expand All @@ -201,7 +201,7 @@ impl Median<f64> for Bernoulli {
///
/// # Formula
///
/// ```ignore
/// ```text
/// if p < 0.5 { 0 }
/// else if p > 0.5 { 1 }
/// else { 0.5 }
Expand All @@ -216,7 +216,7 @@ impl Mode<Option<u64>> for Bernoulli {
///
/// # Formula
///
/// ```ignore
/// ```text
/// if p < 0.5 { 0 }
/// else { 1 }
/// ```
Expand All @@ -231,7 +231,7 @@ impl Discrete<u64, f64> for Bernoulli {
///
/// # Formula
///
/// ```ignore
/// ```text
/// if x == 0 { 1 - p }
/// else { p }
/// ```
Expand All @@ -244,7 +244,7 @@ impl Discrete<u64, f64> for Bernoulli {
///
/// # Formula
///
/// ```ignore
/// ```text
/// else if x == 0 { ln(1 - p) }
/// else { ln(p) }
/// ```
Expand Down
Loading