Skip to content

Commit

Permalink
DOC: update inverse CDF docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
ColmTalbot committed Aug 13, 2024
1 parent 7248896 commit f988aae
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/distribution/chi_squared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl ContinuousCDF<f64, f64> for ChiSquared {
/// # Formula
///
/// ```text
/// (1 / Γ(k / 2)) * γ(k / 2, x / 2)
/// γ^{-1}(k / 2, x * Γ(k / 2) / 2)
/// ```
///
/// where `k` is the degrees of freedom, `Γ` is the gamma function,
Expand Down
11 changes: 11 additions & 0 deletions src/distribution/erlang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ impl ContinuousCDF<f64, f64> for Erlang {
self.g.sf(x)
}

/// Calculates the inverse cumulative distribution function for the erlang
/// distribution at `x`
///
/// # Formula
///
/// ```text
/// γ^{-1}(k, (k - 1)! x) / λ
/// ```
///
/// where `k` is the shape, `λ` is the rate, and `γ` is the upper
/// incomplete gamma function
fn inverse_cdf(&self, p: f64) -> f64 {
self.g.inverse_cdf(p)
}

Check warning on line 139 in src/distribution/erlang.rs

View check run for this annotation

Codecov / codecov/patch

src/distribution/erlang.rs#L137-L139

Added lines #L137 - L139 were not covered by tests
Expand Down
3 changes: 2 additions & 1 deletion src/distribution/fisher_snedecor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ impl ContinuousCDF<f64, f64> for FisherSnedecor {
/// # Formula
///
/// ```text
/// I_((d1 * x) / (d1 * x + d2))(d1 / 2, d2 / 2)
/// z = I^{-1}_(x)(d1 / 2, d2 / 2)
/// d2 / (d1 (1 / z - 1))
/// ```
///
/// where `d1` is the first degree of freedom, `d2` is
Expand Down
6 changes: 3 additions & 3 deletions src/distribution/triangular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl ContinuousCDF<f64, f64> for Triangular {
/// if x < (mode - min) / (max - min) {
/// min + ((max - min) * (mode - min) * x)^(1 / 2)
/// } else {
/// max - (1 - (max - min) * (max - mode) * x)^(1 / 2)
/// max - ((max - min) * (max - mode) * (1 - x))^(1 / 2)
/// }
/// ```
fn inverse_cdf(&self, p: f64) -> f64 {
Expand All @@ -157,9 +157,9 @@ impl ContinuousCDF<f64, f64> for Triangular {
}

if p < (c - a) / (b - a) {
a + ((c - a) * (b - a) * p).powf(0.5)
a + ((c - a) * (b - a) * p).sqrt()
} else {
b - ((b - a) * (b - c) * (1.0 - p)).powf(0.5)
b - ((b - a) * (b - c) * (1.0 - p)).sqrt()
}
}
}
Expand Down

0 comments on commit f988aae

Please sign in to comment.