Skip to content

Commit

Permalink
Tweak beta computation in the Gamma distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed May 8, 2024
1 parent 709d9dc commit 7167d55
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions rand_distr/src/gamma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,12 @@ where
if a > F::one() {
// Algorithm BB
let alpha = a + b;
let beta =
((alpha - F::from(2.).unwrap()) / (F::from(2.).unwrap() * a * b - alpha)).sqrt();

let two = F::from(2.).unwrap();
let beta_numer = alpha - two;
let beta_denom = two * a * b - alpha;
let beta = (beta_numer / beta_denom).sqrt();

let gamma = a + F::one() / beta;

Ok(Beta {
Expand Down

0 comments on commit 7167d55

Please sign in to comment.