Skip to content

Commit

Permalink
fix: mode for gamma distribution is 0 for shape<=1
Browse files Browse the repository at this point in the history
  • Loading branch information
YeungOnion committed Apr 8, 2024
1 parent 5411ba7 commit aad2fd8
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/distribution/gamma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,13 @@ impl ContinuousCDF<f64, f64> for Gamma {
fn sf(&self, x: f64) -> f64 {
if x <= 0.0 {
1.0
}
else if ulps_eq!(x, self.shape) && self.rate.is_infinite() {
} else if ulps_eq!(x, self.shape) && self.rate.is_infinite() {
0.0
}
else if self.rate.is_infinite() {
} else if self.rate.is_infinite() {
1.0
}
else if x.is_infinite() {
} else if x.is_infinite() {
0.0
}
else {
} else {
gamma::gamma_ur(self.shape, x * self.rate)
}
}
Expand Down Expand Up @@ -239,13 +235,17 @@ impl Mode<Option<f64>> for Gamma {
///
/// # Formula
///
/// ```ignore
/// (α - 1) / β
/// ```text
/// max{(α - 1) / β, 0}
/// ```
///
/// where `α` is the shape and `β` is the rate
fn mode(&self) -> Option<f64> {
Some((self.shape - 1.0) / self.rate)
if self.shape < 1.0 {
Some((self.shape - 1.0) / self.rate)
} else {
Some(0.0)
}
}
}

Expand Down

0 comments on commit aad2fd8

Please sign in to comment.