JuliaStats / Distributions.jl

A Julia package for probability distributions and associated functions.
Other
1.08k stars 410 forks source link

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

Open getzdan opened 7 months ago

getzdan commented 7 months ago

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 commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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

:loudspeaker: Thoughts on this report? Let us know!