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

Change comparison operator to avoid problematic p=0 edge case #1799

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

getzdan
Copy link

@getzdan getzdan commented Nov 12, 2023

Since rand() has been (at this point) agreed to return a value in [0,1) , there is the remote possibility of returning true when sampling a Bernoulli(0.0) distribution if we use <=. Changing this to < removes this possibility.

On the other side of [0,1) , Bernoulli(1.0) still always returns true as expected.

An argument against accepting this PR might be the change in probability of returning true on all intermediate values. As the sampling is not mathematically perfect but limited to computer representation, the current rand() might be closer to mathematical Bernoulli(p) with <=.

@codecov-commenter
Copy link

codecov-commenter commented Nov 12, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.19%. Comparing base (07d1e78) to head (6ae92fa).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1799   +/-   ##
=======================================
  Coverage   86.19%   86.19%           
=======================================
  Files         146      146           
  Lines        8767     8768    +1     
=======================================
+ Hits         7557     7558    +1     
  Misses       1210     1210           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Successfully merging this pull request may close these issues.

3 participants