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

Add distribution plots to rand_distr documentation #1434

Merged
merged 30 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9b02d66
Intermediate solution
MichaelOwenDyer Apr 8, 2024
2ea1da3
First few diagrams added
MichaelOwenDyer Apr 9, 2024
3187495
Remove bernoulli.png, move python src to diagrams folder, add more di…
MichaelOwenDyer Apr 10, 2024
e4cfd9d
Embed more diagrams
MichaelOwenDyer Apr 10, 2024
52719b4
Add back python code in new dir
MichaelOwenDyer Apr 10, 2024
f656d82
Switch to svg files
MichaelOwenDyer Apr 10, 2024
bcc0228
Exclude py src from package
MichaelOwenDyer Apr 10, 2024
6dc035c
Add python method stubs for all dists
MichaelOwenDyer Apr 10, 2024
00ba897
Remove python and embedding
MichaelOwenDyer Apr 10, 2024
6bc8145
Remove plots
MichaelOwenDyer Apr 10, 2024
741d82e
Documentation binomial to hypergeometric
MichaelOwenDyer Apr 11, 2024
af53cb2
Add rest of plots
MichaelOwenDyer May 24, 2024
91028d2
Merge branch 'refs/heads/master' into dist-diagrams-in-docs
MichaelOwenDyer May 24, 2024
92010f2
Update documentation
MichaelOwenDyer Jun 16, 2024
5bb4635
Rustfmt
MichaelOwenDyer Jun 16, 2024
0ff93c9
Update CHANGELOG.md
MichaelOwenDyer Jun 16, 2024
6d3f241
Implement feedback
MichaelOwenDyer Jun 18, 2024
4f201ba
Update documentation for t-distribution
MichaelOwenDyer Jun 18, 2024
c1342f3
Update documentation for StudentT::new
MichaelOwenDyer Jun 18, 2024
1fa94f6
Update documentation
MichaelOwenDyer Jun 18, 2024
2d8de9a
Update documentation
MichaelOwenDyer Jun 19, 2024
2319a65
Update Inverse Gaussian and Normal
MichaelOwenDyer Jun 22, 2024
9829ca1
Update documentation
MichaelOwenDyer Jul 8, 2024
74ec228
Add Wikipedia links
MichaelOwenDyer Jul 8, 2024
e105c59
Consistency
MichaelOwenDyer Jul 8, 2024
6165645
fmt
MichaelOwenDyer Jul 8, 2024
b1f5252
Change order of Frechet parameters
MichaelOwenDyer Jul 8, 2024
00503f4
Fix Pareto parameters
MichaelOwenDyer Jul 8, 2024
4428023
Fix ξ name
MichaelOwenDyer Jul 8, 2024
4a880b8
Add skew normal wikipedia link
MichaelOwenDyer Jul 8, 2024
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
12 changes: 6 additions & 6 deletions rand_distr/src/gumbel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! The Gumbel distribution `Gumbel(μ, σ)`.
//! The Gumbel distribution `Gumbel(μ, β)`.

use crate::{Distribution, OpenClosed01};
use core::fmt;
use num_traits::Float;
use rand::Rng;

/// The Gumbel distribution `Gumbel(μ, σ)`.
/// The Gumbel distribution `Gumbel(μ, β)`.
///
/// The Gumbel distribution is a continuous probability distribution
/// with location parameter `μ` and scale parameter `σ`.
/// with location parameter `μ` (`mu`) and scale parameter `β` (`beta`).
/// It is used to model the distribution of the maximum (or minimum)
/// of a number of samples of various distributions.
///
/// # Density function
///
/// `f(x) = exp(-(z + exp(-z))) / σ`, where `z = (x - μ) / σ`.
/// `f(x) = exp(-(z + exp(-z))) / β`, where `z = (x - μ) / β`.
///
/// # Plot
///
/// The following plot illustrates the Gumbel distribution with various values of `μ` and `σ`.
/// The following plot illustrates the Gumbel distribution with various values of `μ` and `β`.
/// Note how the location parameter `μ` shifts the distribution along the x-axis,
/// and the scale parameter `σ` changes the density around `μ`.
/// and the scale parameter `β` changes the density around `μ`.
/// Note also the asymptotic behavior of the distribution towards the right.
///
/// ![Gumbel distribution](https://raw.githubusercontent.com/rust-random/charts/main/charts/gumbel.svg)
Expand Down
8 changes: 4 additions & 4 deletions rand_distr/src/pareto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! The Pareto distribution.
//! The Pareto distribution `Pareto(α, xₘ)`.

use crate::{Distribution, OpenClosed01};
use core::fmt;
use num_traits::Float;
use rand::Rng;

/// The Pareto distribution `Pareto(scale, shape)`.
/// The Pareto distribution `Pareto(α, xₘ)`.
///
/// The Pareto distribution is a continuous probability distribution with
/// parameters `scale` (`α`) and `shape` (`x`<sub>`m`</sub> or `k`).
/// parameters `scale` (`α`) and `shape` (`xₘ` or `k`).
///
/// # Plot
///
/// The following plot shows the Pareto distribution with various values of
/// `scale` and `shape`.
/// Note how the scale parameter `α` corresponds to the height of the jump
/// in density at `x = x`<sub>`m`</sub>, and to the rate of decay in the tail.
/// in density at `x = xₘ`, and to the rate of decay in the tail.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the parameter names got confused somewhere — looks like α is shape. Also, match argument order of the constructor: scale comes first.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I think I fixed it; please take another look. The plot still lists them in the other order (α, xₘ) but I guess that's okay.

///
/// ![Pareto distribution](https://raw.githubusercontent.com/rust-random/charts/main/charts/pareto.svg)
///
Expand Down
6 changes: 3 additions & 3 deletions rand_distr/src/poisson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! The Poisson distribution.
//! The Poisson distribution `Poisson(λ)`.

use crate::{Cauchy, Distribution, Standard};
use core::fmt;
use num_traits::{Float, FloatConst};
use rand::Rng;

/// The Poisson distribution `Poisson(lambda)`.
/// The Poisson distribution `Poisson(λ)`.
///
/// The Poisson distribution is a discrete probability distribution with
/// rate parameter `λ`. It models the number of events occurring in a fixed
/// rate parameter `λ` (lambda). It models the number of events occurring in a fixed
/// interval of time or space.
///
/// This distribution has density function:
Expand Down
14 changes: 9 additions & 5 deletions rand_distr/src/skew_normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! The Skew Normal distribution.
//! The Skew Normal distribution `SN(ξ, ω, α)`.

use crate::{Distribution, StandardNormal};
use core::fmt;
use num_traits::Float;
use rand::Rng;

/// The [skew normal distribution] `SN(location, scale, shape)`.
/// The [skew normal distribution] `SN(ξ, ω, α)`.
///
/// The skew normal distribution is a generalization of the
/// [`Normal`](crate::Normal) distribution to allow for non-zero skewness.
/// It has parameters `location` (`ξ`, zeta), `scale` (`ω`, omega), and
/// `shape` (`α`, alpha).
///
/// The `location` and `scale` parameters correspond to the
/// mean and standard deviation of the normal distribution,
/// respectively. The `shape` parameter controls the skewness.
/// The `ξ` and `ω` parameters correspond to the mean `μ` and standard
/// deviation `σ` of the normal distribution, respectively.
/// The `α` parameter controls the skewness.
///
/// # Density function
///
/// It has the density function, for `scale > 0`,
/// `f(x) = 2 / scale * phi((x - location) / scale) * Phi(alpha * (x - location) / scale)`
Expand Down
8 changes: 5 additions & 3 deletions rand_distr/src/weibull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! The Weibull distribution.
//! The Weibull distribution `Weibull(λ, k)`

use crate::{Distribution, OpenClosed01};
use core::fmt;
use num_traits::Float;
use rand::Rng;

/// Samples floating-point numbers according to the Weibull distribution.
/// The Weibull distribution has two parameters, `scale` (`λ`) and `shape` (`k`).
/// The Weibull distribution `Weibull(λ, k)`.
/// This is a family of continuous probability distributions with parameters
/// `scale` (`λ`, lambda) and `shape` (`k`). It is used to model reliability
/// data, life data, and accelerated life testing data.
///
/// # Plot
///
Expand Down
23 changes: 12 additions & 11 deletions rand_distr/src/zipf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ use rand::{distributions::OpenClosed01, Rng};

/// The Zeta distribution `Zeta(a)`.
///
/// The Zeta distribution is a discrete probability distribution with parameter
/// `a`. It is a special case of the [`Zipf`] distribution with `n = ∞`.
/// The [Zeta distribution](https://en.wikipedia.org/wiki/Zeta_distribution)
/// is a discrete probability distribution with parameter `a`.
/// It is a special case of the [`Zipf`] distribution with `n = ∞`.
/// It is also known as the discrete Pareto, Riemann-Zeta, Zipf, or Zipf–Estoup distribution.
///
/// It has the density function `f(k) = k^(-a) / C(a)` for `k >= 1`, where `a`
/// is the parameter and `C(a)` is the Riemann zeta function.
/// # Density function
///
/// `f(k) = k^(-a) / ζ(a)` for `k >= 1`, where `ζ` is the
/// [Riemann zeta function](https://en.wikipedia.org/wiki/Riemann_zeta_function).
///
/// # Plot
///
Expand All @@ -37,7 +40,7 @@ use rand::{distributions::OpenClosed01, Rng};
/// println!("{}", val);
/// ```
///
/// # Remarks
/// # Notes
///
/// The zeta distribution has no upper limit. Sampled values may be infinite.
/// In particular, a value of infinity might be returned for the following
Expand All @@ -47,11 +50,9 @@ use rand::{distributions::OpenClosed01, Rng};
///
/// # Implementation details
///
/// We are using the algorithm from [Non-Uniform Random Variate Generation],
/// We are using the algorithm from
/// [Non-Uniform Random Variate Generation](https://doi.org/10.1007/978-1-4613-8643-8),
/// Section 6.1, page 551.
///
/// [zeta distribution]: https://en.wikipedia.org/wiki/Zeta_distribution
/// [Non-Uniform Random Variate Generation]: https://doi.org/10.1007/978-1-4613-8643-8
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Zeta<F>
where
Expand Down Expand Up @@ -131,13 +132,13 @@ where
}
}

/// Samples integers according to the Zipf distribution.
/// The Zipf distribution `Zipf(n, s)`.
///
/// The samples follow Zipf's law: The frequency of each sample from a finite
/// set of size `n` is inversely proportional to a power of its frequency rank
/// (with exponent `s`).
///
/// For large `n`, this converges to the [`Zeta`] distribution.
/// For large `n`, this converges to the [`Zeta`](crate::Zeta) distribution.
///
/// For `s = 0`, this becomes a uniform distribution.
///
Expand Down
Loading