Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Bug. Infinite loop in Binomial Distribution #1324

Closed
benjamin-lieser opened this issue Jul 4, 2023 · 2 comments
Closed

Bug. Infinite loop in Binomial Distribution #1324

benjamin-lieser opened this issue Jul 4, 2023 · 2 comments

Comments

@benjamin-lieser
Copy link
Member

With the current master branch and the values of
n = 16000000 and
p = 3.1444753148558566e-10
for the Binomial distribution

it got stuck in an infinite loop in the BINV algorithm

I know its not reproducible because you need to get an unlucky random number for it to happen. But it is described in the GSL source code https://github.com/ampl/gsl/blob/47862078af4a204c4220f028656a19ddd3922144/randist/binomial_tpe.c#L100

@vks
Copy link
Collaborator

vks commented Jul 4, 2023

Thanks for the report! I managed to reproduce it with this program:

use rand::SeedableRng;
use rand::distributions::Distribution;

fn main() {
    let dist = rand_distr::Binomial::new(16000000, 3.1444753148558566e-10).unwrap();
    let mut sum: u64 = 0;
    let seed = 2569;
    let mut rng = rand_xoshiro::Xoshiro256PlusPlus::seed_from_u64(seed);
    for _ in 0..100_000 {
        sum = sum.wrapping_add(dist.sample(&mut rng));
    }
    println!("sum: {}", sum);
}

@vks
Copy link
Collaborator

vks commented Jul 4, 2023

Here is a reproduction using the internal test::rng:

use rand::distributions::Distribution;

pub fn rng(seed: u64) -> impl rand::RngCore {
    const INC: u64 = 11634580027462260723;
    rand_pcg::Pcg32::new(seed, INC)
}

fn main() {
    let dist = rand_distr::Binomial::new(16000000, 3.1444753148558566e-10).unwrap();
    let mut sum: u64 = 0;
    let seed = 742;
    let mut rng = rng(seed);
    for _ in 0..100_000 {
        sum = sum.wrapping_add(dist.sample(&mut rng));
    }
    println!("sum: {}", sum);
}

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants