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 1 commit 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 ✅

Files Coverage Δ
src/univariate/discrete/bernoulli.jl 89.85% <100.00%> (ø)

📢 Thoughts on this report? Let us know!

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.

2 participants