pub struct Exp<F>{ /* private fields */ }Expand description
The exponential distribution Exp(λ).
The exponential distribution is a continuous probability distribution
with rate parameter λ (lambda). It describes the time between events
in a Poisson process, i.e. a process in which
events occur continuously and independently at a constant average rate.
See Exp1 for an optimised implementation for λ = 1.
§Density function
f(x) = λ * exp(-λ * x) for x > 0, when λ > 0.
For λ = 0, all samples yield infinity (because a Poisson process
with rate 0 has no events).
§Plot
The following plot illustrates the exponential distribution with
various values of λ.
The λ parameter controls the rate of decay as x approaches infinity,
and the mean of the distribution is 1/λ.
§Example
use rand_distr::{Exp, Distribution};
let exp = Exp::new(2.0).unwrap();
let v = exp.sample(&mut rand::rng());
println!("{} is from a Exp(2) distribution", v);Implementations§
Source§impl<F> Exp<F>
impl<F> Exp<F>
Sourcepub fn new(lambda: F) -> Result<Exp<F>, Error>
pub fn new(lambda: F) -> Result<Exp<F>, Error>
Construct a new Exp with the given shape parameter
lambda.
§Remarks
For custom types N implementing the Float trait,
the case lambda = 0 is handled as follows: each sample corresponds
to a sample from an Exp1 multiplied by 1 / 0. Primitive types
yield infinity, since 1 / 0 = infinity.
The case lambda = N::neg_zero() returns an error, because -0.0 is typically
produced through underflow of computations with a negative ideal result, and
because 1 / -0.0 = -infinity.