Skip to content

Commit

Permalink
fix binomial cdf, to give 0 for negative numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-lieser committed Sep 30, 2024
1 parent 09fdd60 commit d03ee85
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions rand_distr/tests/cdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn kolmogorov_smirnov_statistic_continuous(ecdf: Ecdf, cdf: impl Fn(f64) -> f64)

fn kolmogorov_smirnov_statistic_discrete(ecdf: Ecdf, cdf: impl Fn(i64) -> f64) -> f64 {
// We implement equation (4) from [1]

let mut max_diff: f64 = 0.;

let step_points = ecdf.step_points(); // x_i in the paper
Expand Down Expand Up @@ -136,9 +136,13 @@ fn normal() {
fn binomial() {
for seed in 1..20 {
test_discrete(seed, rand_distr::Binomial::new(10, 0.5).unwrap(), |x| {
statrs::distribution::Binomial::new(0.5, 10)
.unwrap()
.cdf(x as u64)
if x < 0 {
0.0
} else {
statrs::distribution::Binomial::new(0.5, 10)
.unwrap()
.cdf(x as u64)
}
});
}
}

0 comments on commit d03ee85

Please sign in to comment.