|
7 | 7 | // option. This file may not be copied, modified, or distributed
|
8 | 8 | // except according to those terms.
|
9 | 9 |
|
10 |
| -//! The exponential distribution. |
| 10 | +//! The exponential distribution `Exp(λ)`. |
11 | 11 |
|
12 | 12 | use crate::utils::ziggurat;
|
13 | 13 | use crate::{ziggurat_tables, Distribution};
|
14 | 14 | use core::fmt;
|
15 | 15 | use num_traits::Float;
|
16 | 16 | use rand::Rng;
|
17 | 17 |
|
18 |
| -/// Samples floating-point numbers according to the exponential distribution, |
19 |
| -/// with rate parameter `λ = 1`. This is equivalent to `Exp::new(1.0)` or |
20 |
| -/// sampling with `-rng.gen::<f64>().ln()`, but faster. |
| 18 | +/// The standard exponential distribution `Exp(1)`. |
21 | 19 | ///
|
22 |
| -/// See `Exp` for the general exponential distribution. |
| 20 | +/// This is equivalent to `Exp::new(1.0)` or sampling with |
| 21 | +/// `-rng.gen::<f64>().ln()`, but faster. |
23 | 22 | ///
|
24 |
| -/// Implemented via the ZIGNOR variant[^1] of the Ziggurat method. The exact |
25 |
| -/// description in the paper was adjusted to use tables for the exponential |
26 |
| -/// distribution rather than normal. |
| 23 | +/// See [`Exp`](crate::Exp) for the general exponential distribution. |
27 | 24 | ///
|
28 |
| -/// [^1]: Jurgen A. Doornik (2005). [*An Improved Ziggurat Method to |
29 |
| -/// Generate Normal Random Samples*]( |
30 |
| -/// https://www.doornik.com/research/ziggurat.pdf). |
31 |
| -/// Nuffield College, Oxford |
| 25 | +/// # Plot |
| 26 | +/// |
| 27 | +/// The following plot illustrates the exponential distribution with `λ = 1`. |
| 28 | +/// |
| 29 | +///  |
32 | 30 | ///
|
33 | 31 | /// # Example
|
| 32 | +/// |
34 | 33 | /// ```
|
35 | 34 | /// use rand::prelude::*;
|
36 | 35 | /// use rand_distr::Exp1;
|
37 | 36 | ///
|
38 | 37 | /// let val: f64 = thread_rng().sample(Exp1);
|
39 | 38 | /// println!("{}", val);
|
40 | 39 | /// ```
|
| 40 | +/// |
| 41 | +/// # Notes |
| 42 | +/// |
| 43 | +/// Implemented via the ZIGNOR variant[^1] of the Ziggurat method. The exact |
| 44 | +/// description in the paper was adjusted to use tables for the exponential |
| 45 | +/// distribution rather than normal. |
| 46 | +/// |
| 47 | +/// [^1]: Jurgen A. Doornik (2005). [*An Improved Ziggurat Method to |
| 48 | +/// Generate Normal Random Samples*]( |
| 49 | +/// https://www.doornik.com/research/ziggurat.pdf). |
| 50 | +/// Nuffield College, Oxford |
41 | 51 | #[derive(Clone, Copy, Debug)]
|
42 | 52 | #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
|
43 | 53 | pub struct Exp1;
|
@@ -75,12 +85,30 @@ impl Distribution<f64> for Exp1 {
|
75 | 85 | }
|
76 | 86 | }
|
77 | 87 |
|
78 |
| -/// The exponential distribution `Exp(lambda)`. |
| 88 | +/// The [exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution) `Exp(λ)`. |
| 89 | +/// |
| 90 | +/// The exponential distribution is a continuous probability distribution |
| 91 | +/// with rate parameter `λ` (`lambda`). It describes the time between events |
| 92 | +/// in a [`Poisson`](crate::Poisson) process, i.e. a process in which |
| 93 | +/// events occur continuously and independently at a constant average rate. |
| 94 | +/// |
| 95 | +/// See [`Exp1`](crate::Exp1) for an optimised implementation for `λ = 1`. |
| 96 | +/// |
| 97 | +/// # Density function |
| 98 | +/// |
| 99 | +/// `f(x) = λ * exp(-λ * x)` for `x > 0`, when `λ > 0`. |
| 100 | +/// |
| 101 | +/// For `λ = 0`, all samples yield infinity (because a Poisson process |
| 102 | +/// with rate 0 has no events). |
| 103 | +/// |
| 104 | +/// # Plot |
79 | 105 | ///
|
80 |
| -/// This distribution has density function: `f(x) = lambda * exp(-lambda * x)` |
81 |
| -/// for `x > 0`, when `lambda > 0`. For `lambda = 0`, all samples yield infinity. |
| 106 | +/// The following plot illustrates the exponential distribution with |
| 107 | +/// various values of `λ`. |
| 108 | +/// The `λ` parameter controls the rate of decay as `x` approaches infinity, |
| 109 | +/// and the mean of the distribution is `1/λ`. |
82 | 110 | ///
|
83 |
| -/// Note that [`Exp1`](crate::Exp1) is an optimised implementation for `lambda = 1`. |
| 111 | +///  |
84 | 112 | ///
|
85 | 113 | /// # Example
|
86 | 114 | ///
|
|
0 commit comments