0
當使用clang++
實現std::binomial_distribution
,我看到了一些非常不滿的行爲:C++ 11的std :: binomial_distribution不穩定
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;
}
下面是結果:
254 ≈ 250
340 ≈ 333.333
598 ≈ 600
628 ≈ 1000 # WAT? - should be around 1000
很奇怪的是,如果你嘗試撥打binomial_distribution<int>(100, p[3])
,它永遠掛起。這後一種行爲後來是不受歡迎的,但預計 - 成功的可能性不應該超過1
。
如果您想知道,p
的上述值來自使用conditional binomial method修改gsl_ran_multinomial
來生成多項式變量。
我的編譯器是clang++
下El Capitan 10.11.4
Apple LLVM version 7.3.0 (clang-703.0.29)
Target: x86_64-apple-darwin15.4.0
謝謝!
有道理。我想我真的很想抱怨。 – Manbroski