pub struct Zeta<F>{ /* private fields */ }
Expand description
The Zeta distribution Zeta(s)
.
The Zeta distribution
is a discrete probability distribution with parameter s
.
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.
§Density function
f(k) = k^(-s) / ζ(s)
for k >= 1
, where ζ
is the
Riemann zeta function.
§Plot
The following plot illustrates the zeta distribution for various values of s
.
§Example
use rand::prelude::*;
use rand_distr::Zeta;
let val: f64 = rand::rng().sample(Zeta::new(1.5).unwrap());
println!("{}", val);
§Integer vs FP return type
This implementation uses floating-point (FP) logic internally, which can
potentially generate very large samples (exceeding e.g. u64::MAX
).
It is safe to cast such results to an integer type using as
(e.g. distr.sample(&mut rng) as u64
), since such casts are saturating
(e.g. 2f64.powi(64) as u64 == u64::MAX
). It is up to the user to
determine whether this potential loss of accuracy is acceptable
(this determination may depend on the distribution’s parameters).
§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 reasons:
- it is the best representation in the type
F
of the actual sample. - to prevent infinite loops for very small
s
.
§Implementation details
We are using the algorithm from Non-Uniform Random Variate Generation, Section 6.1, page 551.