Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rand_distr: Add Zipf distribution #1136

Merged
merged 26 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0360aa9
rand_distr: Add Zipf distribution
vks Jun 13, 2021
1e1e768
Update changelog
vks Jun 13, 2021
a57247d
Zipf: Use `OpenClosed01`
vks Jun 15, 2021
718e71b
Zipf: Add benchmark
vks Jun 15, 2021
c2ecf1b
Fix value stability tests
vks Jun 15, 2021
6c27184
Rename `Zipf` to `Zeta`
vks Jun 15, 2021
b06c2f6
Don't claim `Zeta` follows Zipf's law
vks Jun 15, 2021
a07b321
rand_distr: Add Zipf (not zeta) distribution
vks Jun 15, 2021
6270248
Zipf: Fix `s = 1` special case
vks Jun 16, 2021
4d67af2
Zipf: Mention that rounding may occur
vks Jun 16, 2021
139e898
Zipf: Simplify trait bounds
vks Jun 16, 2021
f514fd6
Zipf: Simplify calculation of ratio
vks Jun 16, 2021
ccaa4de
Zipf: Update benchmarks
vks Jun 16, 2021
3cccc64
Zeta: Inline distribution methods
vks Jun 16, 2021
14d55f8
Group `Zeta` and `Zipf` with rate-related distributions
vks Jun 16, 2021
85f55b2
Zeta and Zipf: Improve docs
vks Jul 27, 2021
2a33433
Zeta: Replace likely impossible if with debug_assert
vks Jul 27, 2021
e19349c
Give credit for implementation details
vks Jul 28, 2021
a746fd2
Zipf: Fix `inv_cdf` for `s = 1`
vks Jul 28, 2021
b053683
Zipf: Correctly calculate rejection ratio
vks Jul 28, 2021
0f9243c
Zipf: Add debug_assert for invariant
vks Jul 28, 2021
e5aff9a
Zipf: Avoid division inside loop
vks Jul 30, 2021
a32cd08
Zeta: Mention algorithm in doc comment
vks Jul 30, 2021
72a6333
Zeta: Avoid division in rejection criterion
vks Jul 30, 2021
cf4b7e4
Zeta: Fix infinite loop for small `a`
vks Aug 2, 2021
fe5a6e1
Zeta: Document cases where infinity is returned
vks Aug 3, 2021
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
3 changes: 3 additions & 0 deletions rand_distr/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
- New `Zeta` and `Zipf` distributions (#1136)

## [0.4.1] - 2021-06-15
- Empirically test PDF of normal distribution (#1121)
- Correctly document `no_std` support (#1100)
Expand Down
6 changes: 6 additions & 0 deletions rand_distr/benches/src/distributions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ fn bench(c: &mut Criterion<CyclesPerByte>) {
distr_float!(g, "poisson", f64, Poisson::new(4.0).unwrap());
}

{
let mut g = c.benchmark_group("zipf");
distr_float!(g, "zipf", f64, Zipf::new(10, 1.5).unwrap());
distr_float!(g, "zeta", f64, Zeta::new(1.5).unwrap());
}

{
let mut g = c.benchmark_group("bernoulli");
distr!(g, "bernoulli", bool, Bernoulli::new(0.18).unwrap());
Expand Down
5 changes: 4 additions & 1 deletion rand_distr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
//! - [`Poisson`] distribution
//! - [`Exp`]onential distribution, and [`Exp1`] as a primitive
//! - [`Weibull`] distribution
//! - [`Zeta`] distribution
//! - [`Zipf`] distribution
//! - Gamma and derived distributions:
//! - [`Gamma`] distribution
//! - [`ChiSquared`] distribution
Expand Down Expand Up @@ -115,6 +117,7 @@ pub use self::unit_circle::UnitCircle;
pub use self::unit_disc::UnitDisc;
pub use self::unit_sphere::UnitSphere;
pub use self::weibull::{Error as WeibullError, Weibull};
pub use self::zipf::{ZetaError, Zeta, ZipfError, Zipf};
#[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
pub use rand::distributions::{WeightedError, WeightedIndex};
Expand Down Expand Up @@ -198,4 +201,4 @@ mod unit_sphere;
mod utils;
mod weibull;
mod ziggurat_tables;

mod zipf;
Loading