Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
ENH: Add the negative binomial distribution to rand_distr. #1296
base: master
Are you sure you want to change the base?
ENH: Add the negative binomial distribution to rand_distr. #1296
Changes from 3 commits
4ece871
93632f2
c459991
43f3d66
cedbd83
7643943
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of
unwrap
, one should take care of the case wheregamma.sample(rng)
returns a float which should not be accepted.I suggest introducing a loop which samples until one gets a finite sample.
The
Float
trait has the methodis_finite
for this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this happen? The Gamma distribution should return strictly positive values, so
Poisson::new
should never fail.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, my point was about handling infinity as the result of simulating the gamma variable.
Nothing ensures that a Gamma samples always a positive and finite float.
Not is the signature of the
sample
method nor in its documentation.At some point there was a discussion about who should handle
infinity
out of the simulation: the library or the user. I thought the decision was that the user should handle infinity floats, maybe I am wrong. This is why I suggest handling a possible infinite value here with a loop.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I need to fix this. If
p
is extremely small (e.g. 1e-40), then the scale passed toGamma
is huge (1e+40), and with such a scale,Gamma
will generate samples that are infinity.A simple loop would not be safe if we don't have a bound on how frequently infinity is generated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was not even thinking on extreme values, just the
unwrap
.The thing is, if gamma samples infinity, then the Poisson "should" also infinity.
Then, instead of a loop, one should introduce an
if
checking if the gamma samples infinity.If it does, return infinity directly, if it does not, sample the Poisson (created with
new
andunwrap
).