diff --git a/src/distribution/gamma.rs b/src/distribution/gamma.rs index d1abf0c2..3fa926b0 100644 --- a/src/distribution/gamma.rs +++ b/src/distribution/gamma.rs @@ -145,7 +145,6 @@ impl ContinuousCDF for Gamma { } fn inverse_cdf(&self, p: f64) -> f64 { - const MAX_ITERS: (u16, u16) = (8, 4); if !(0.0..=1.0).contains(&p) { panic!("default inverse_cdf implementation should be provided probability on [0,1]") } @@ -167,7 +166,7 @@ impl ContinuousCDF for Gamma { } let mut x_0 = (high + low) / 2.0; - for _ in 0..MAX_ITERS.0 { + for _ in 0..8 { if self.cdf(x_0) >= p { high = x_0; } else { @@ -178,8 +177,8 @@ impl ContinuousCDF for Gamma { } } - // NR method, guarantee at least one step - for _ in 0..MAX_ITERS.1 { + // Newton Raphson, for at least one step + for _ in 0..4 { let x_next = x_0 - (self.cdf(x_0) - p) / self.pdf(x_0); if prec::convergence(&mut x_0, x_next) { break;