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

Add bound to HyperGeometric logp (resolves #4366) #4367

Merged
merged 3 commits into from
Dec 22, 2020

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Dec 21, 2020

This PR adds a bound to the HyperGeometric logp, in order to return -inf when given invalid parameters, instead of nan 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 current tt.max and tt.min has any disadvantages compared to the tt.switch that was suggsted before. It seems 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 helper modified_scipy_hypergeom_logpmf function.

@ricardoV94 ricardoV94 changed the title - Add bound to HyperGeometric logp (resolves #4366) Add bound to HyperGeometric logp (resolves #4366) Dec 21, 2020
@codecov
Copy link

codecov bot commented Dec 21, 2020

Codecov Report

Merging #4367 (9f9df0e) into master (0ec65e5) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4367   +/-   ##
=======================================
  Coverage   87.95%   87.95%           
=======================================
  Files          88       88           
  Lines       14491    14493    +2     
=======================================
+ Hits        12746    12748    +2     
  Misses       1745     1745           
Impacted Files Coverage Δ
pymc3/distributions/discrete.py 95.84% <100.00%> (+0.02%) ⬆️

Copy link
Contributor

@tirthasheshpatel tirthasheshpatel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything here looks good to me! Thanks, @ricardoV94!

Copy link
Contributor

@AlexAndorra AlexAndorra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @ricardoV94 !

@AlexAndorra AlexAndorra merged commit 0402aab into pymc-devs:master Dec 22, 2020
@ricardoV94 ricardoV94 deleted the fix_hypergeometric branch December 22, 2020 09:13
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.

None yet

3 participants