Skip to content
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

Add Bernoulli distribution #300

Closed
dhardy opened this issue Mar 14, 2018 · 6 comments
Closed

Add Bernoulli distribution #300

dhardy opened this issue Mar 14, 2018 · 6 comments
Labels
E-easy Participation: easy job F-new-int Functionality: new, within Rand

Comments

@dhardy
Copy link
Member

dhardy commented Mar 14, 2018

Add a Bernoulli distribution (i.e. boolean with probability p).

This is basically just rng.gen() < p, but the uniform distribution used to generate a float has precision limited to ε (smallest representable number above 1); we can do better.

We may decide not to implement this as a distribution but with a simple function calling rng.sample(HighPrecision01) < p or similar.

See also #293: add Rng::gen_bool or similar

@dhardy dhardy added F-new-int Functionality: new, within Rand P-medium labels Mar 14, 2018
@pitdicker
Copy link
Contributor

We went with Rng::gen_bool, so I think this can be closed.

@pitdicker
Copy link
Contributor

After some discussion (#347) we probably still want a Bernoulli distribution, that provides more than 32 bits of accuracy. I.e. that uses rng.sample(HighPrecision01) < p.

@pitdicker pitdicker reopened this Apr 2, 2018
@pitdicker pitdicker added E-easy Participation: easy job and removed P-medium labels Apr 2, 2018
@vks
Copy link
Collaborator

vks commented Apr 11, 2018

I'm working on a PR.

What is the reasoning behind Rng::gen_bool and Bernoulli::sample having different accuracies? This seems confusing, if we want to support different accuracies, I think we should also have different distributions, i.e. BernoulliHighPrecision and BernoulliLowPrecision.

@pitdicker
Copy link
Contributor

@vks. Good that you want to make a PR!

As you have been following this repro pretty closely, I think I can ask you this. Making the PR for this distribution is trivial. Before that, can you provide links to the relevant discussions there have been on this issue, and summarize the concerns and possible implementations?

@dhardy
Copy link
Member Author

dhardy commented Apr 11, 2018

AFAIK the only advantage of the lower precision variant using "only" 32 bits is that more optimisation can be done when p is a known constant to the compiler — otherwise the version using HighPrecision01 with 52-bits fraction has similar performance (at least in my benches).

@vks
Copy link
Collaborator

vks commented Apr 11, 2018

Those are the only discussions about gen_bool I found: #293, #308, #347

vks added a commit to vks/rand that referenced this issue Apr 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Participation: easy job F-new-int Functionality: new, within Rand
Projects
None yet
Development

No branches or pull requests

3 participants