summaryrefslogtreecommitdiff
path: root/rand/src/distributions/gamma.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rand/src/distributions/gamma.rs')
-rw-r--r--rand/src/distributions/gamma.rs90
1 files changed, 24 insertions, 66 deletions
diff --git a/rand/src/distributions/gamma.rs b/rand/src/distributions/gamma.rs
index 43ac2bc..b5a97f5 100644
--- a/rand/src/distributions/gamma.rs
+++ b/rand/src/distributions/gamma.rs
@@ -8,13 +8,14 @@
// except according to those terms.
//! The Gamma and derived distributions.
+#![allow(deprecated)]
use self::GammaRepr::*;
use self::ChiSquaredRepr::*;
-use Rng;
-use distributions::normal::StandardNormal;
-use distributions::{Distribution, Exp, Open01};
+use crate::Rng;
+use crate::distributions::normal::StandardNormal;
+use crate::distributions::{Distribution, Exp, Open01};
/// The Gamma distribution `Gamma(shape, scale)` distribution.
///
@@ -32,20 +33,11 @@ use distributions::{Distribution, Exp, Open01};
/// == 1`, and using the boosting technique described in that paper for
/// `shape < 1`.
///
-/// # Example
-///
-/// ```
-/// use rand::distributions::{Distribution, Gamma};
-///
-/// let gamma = Gamma::new(2.0, 5.0);
-/// let v = gamma.sample(&mut rand::thread_rng());
-/// println!("{} is from a Gamma(2, 5) distribution", v);
-/// ```
-///
/// [^1]: George Marsaglia and Wai Wan Tsang. 2000. "A Simple Method for
/// Generating Gamma Variables" *ACM Trans. Math. Softw.* 26, 3
/// (September 2000), 363-372.
/// DOI:[10.1145/358407.358414](https://doi.acm.org/10.1145/358407.358414)
+#[deprecated(since="0.7.0", note="moved to rand_distr crate")]
#[derive(Clone, Copy, Debug)]
pub struct Gamma {
repr: GammaRepr,
@@ -174,16 +166,7 @@ impl Distribution<f64> for GammaLargeShape {
/// of `k` independent standard normal random variables. For other
/// `k`, this uses the equivalent characterisation
/// `χ²(k) = Gamma(k/2, 2)`.
-///
-/// # Example
-///
-/// ```
-/// use rand::distributions::{ChiSquared, Distribution};
-///
-/// let chi = ChiSquared::new(11.0);
-/// let v = chi.sample(&mut rand::thread_rng());
-/// println!("{} is from a χ²(11) distribution", v)
-/// ```
+#[deprecated(since="0.7.0", note="moved to rand_distr crate")]
#[derive(Clone, Copy, Debug)]
pub struct ChiSquared {
repr: ChiSquaredRepr,
@@ -229,16 +212,7 @@ impl Distribution<f64> for ChiSquared {
/// This distribution is equivalent to the ratio of two normalised
/// chi-squared distributions, that is, `F(m,n) = (χ²(m)/m) /
/// (χ²(n)/n)`.
-///
-/// # Example
-///
-/// ```
-/// use rand::distributions::{FisherF, Distribution};
-///
-/// let f = FisherF::new(2.0, 32.0);
-/// let v = f.sample(&mut rand::thread_rng());
-/// println!("{} is from an F(2, 32) distribution", v)
-/// ```
+#[deprecated(since="0.7.0", note="moved to rand_distr crate")]
#[derive(Clone, Copy, Debug)]
pub struct FisherF {
numer: ChiSquared,
@@ -270,16 +244,7 @@ impl Distribution<f64> for FisherF {
/// The Student t distribution, `t(nu)`, where `nu` is the degrees of
/// freedom.
-///
-/// # Example
-///
-/// ```
-/// use rand::distributions::{StudentT, Distribution};
-///
-/// let t = StudentT::new(11.0);
-/// let v = t.sample(&mut rand::thread_rng());
-/// println!("{} is from a t(11) distribution", v)
-/// ```
+#[deprecated(since="0.7.0", note="moved to rand_distr crate")]
#[derive(Clone, Copy, Debug)]
pub struct StudentT {
chi: ChiSquared,
@@ -305,16 +270,7 @@ impl Distribution<f64> for StudentT {
}
/// The Beta distribution with shape parameters `alpha` and `beta`.
-///
-/// # Example
-///
-/// ```
-/// use rand::distributions::{Distribution, Beta};
-///
-/// let beta = Beta::new(2.0, 5.0);
-/// let v = beta.sample(&mut rand::thread_rng());
-/// println!("{} is from a Beta(2, 5) distribution", v);
-/// ```
+#[deprecated(since="0.7.0", note="moved to rand_distr crate")]
#[derive(Clone, Copy, Debug)]
pub struct Beta {
gamma_a: Gamma,
@@ -345,30 +301,32 @@ impl Distribution<f64> for Beta {
#[cfg(test)]
mod test {
- use distributions::Distribution;
+ use crate::distributions::Distribution;
use super::{Beta, ChiSquared, StudentT, FisherF};
+ const N: u32 = 100;
+
#[test]
fn test_chi_squared_one() {
let chi = ChiSquared::new(1.0);
- let mut rng = ::test::rng(201);
- for _ in 0..1000 {
+ let mut rng = crate::test::rng(201);
+ for _ in 0..N {
chi.sample(&mut rng);
}
}
#[test]
fn test_chi_squared_small() {
let chi = ChiSquared::new(0.5);
- let mut rng = ::test::rng(202);
- for _ in 0..1000 {
+ let mut rng = crate::test::rng(202);
+ for _ in 0..N {
chi.sample(&mut rng);
}
}
#[test]
fn test_chi_squared_large() {
let chi = ChiSquared::new(30.0);
- let mut rng = ::test::rng(203);
- for _ in 0..1000 {
+ let mut rng = crate::test::rng(203);
+ for _ in 0..N {
chi.sample(&mut rng);
}
}
@@ -381,8 +339,8 @@ mod test {
#[test]
fn test_f() {
let f = FisherF::new(2.0, 32.0);
- let mut rng = ::test::rng(204);
- for _ in 0..1000 {
+ let mut rng = crate::test::rng(204);
+ for _ in 0..N {
f.sample(&mut rng);
}
}
@@ -390,8 +348,8 @@ mod test {
#[test]
fn test_t() {
let t = StudentT::new(11.0);
- let mut rng = ::test::rng(205);
- for _ in 0..1000 {
+ let mut rng = crate::test::rng(205);
+ for _ in 0..N {
t.sample(&mut rng);
}
}
@@ -399,8 +357,8 @@ mod test {
#[test]
fn test_beta() {
let beta = Beta::new(1.0, 2.0);
- let mut rng = ::test::rng(201);
- for _ in 0..1000 {
+ let mut rng = crate::test::rng(201);
+ for _ in 0..N {
beta.sample(&mut rng);
}
}