-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement an exact Bernoulli distribution #1193
Comments
There are different approaches to use with irrational Bernoulli probabilities than with rational Bernoulli probabilities. Rational probabilities can be handled by generating an integer with the range of the denominator and then comparing. Your repository could work as well, but I haven't reviewed it enough to say whether it supports arbitrary precision. Irrational probabilities require specialized algorithms, and I discuss many of them in "Bernoulli Factory Algorithms". |
To sample with perfect precision, yes. But if some level of bias is considered acceptable (e.g. no more than 1 in 2^48 samples affected, as used in #1287), then some simplification should be possible? (For this, is just using |
For "biased" Bernoulli sampling, better to find a rational approximation of the Bernoulli probability in question, and for an approximation error of By the way:
|
Background
The current implementation has a probability limit of
1 / (2^32-1)
for the integer constructor and a limit of1 / (2^64)
for the f64 constructor. Assuming a couple nanoseconds per flip, the former's precision limitation could become visible even with only a single core in a matter of seconds. The latter is certainly more robust, taking at least a thousand or so processor-years, but even then distributed computing environments could conceivably reach this precision limitation within a few months.Feature request
Implement an exact Bernoulli distribution. I have created an implementation which I'd be glad to send out a PR to integrate. Mostly looking for feedback if that is desirable before doing so.
The text was updated successfully, but these errors were encountered: