jeudi 21 avril 2016

C 11 std::binomial_distribution is unstable

When using std::binomial_distribution implemented by clang++, I am seeing some very unhappy behaviour:

default_random_engine rng;

vector<double> p{0.2500000000000000000000000000000000000000,
                 0.3333333333333333148296162562473909929395,
                 0.5999999999999999777955395074968691915274,
                 1.0000000000000002220446049250313080847263};

for (auto &i : p) {
  binomial_distribution<int> binom(1000, i);
  cout << binom(rng) << " ≈ " << 1000 * i << endl;
}

Here is the result:

254 ≈ 250
340 ≈ 333.333
598 ≈ 600
628 ≈ 1000 # WAT? - should be around 1000

Quite curiously, if you try to call binomial_distribution<int>(100, p[3]), it hangs forever. This latter behaviour later is undesirable, but expected - the probability of success should not exceed 1.

In case you are wondering, the above values of p come from generating multinomial variates using conditional binomial method in adapting gsl_ran_multinomial.

My compiler is clang++ under El Capitan 10.11.4

Apple LLVM version 7.3.0 (clang-703.0.29)
Target: x86_64-apple-darwin15.4.0

Thanks!




Aucun commentaire:

Enregistrer un commentaire