Add bound to HyperGeometric logp (resolves #4366) #4367
Merged
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.
This PR adds a bound to the
HyperGeometric logp
, in order to return-inf
when given invalid parameters, instead ofnan
or sometimes wrong results (see #4366).I am using the bounds suggested by @tirthasheshpatel in here, which seem to be the support bounds described in the Wikipedia entry.
I am not sure whether the currentIt seemstt.max
andtt.min
has any disadvantages compared to thett.switch
that was suggsted before.tt.switch
deals better with weird parameter shapes...To pass the unit tests, it was necessary to replace the
nan
output of the scipy.hypergeom to-inf
. I decided to simply wrap the original scipy function in the helpermodified_scipy_hypergeom_logpmf
function.