Skip to content

Add Hurdle distributions #6688

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

Merged
merged 3 commits into from
May 10, 2023
Merged

Conversation

tomicapretto
Copy link
Contributor

@tomicapretto tomicapretto commented Apr 25, 2023

What is this PR about?

Implements four hurdle distributions. These are like zero-inflated distributions, but the process that generates the zeroes is independent of the process that generates the non-zero values (in zero-inflated distributions the zeros can come from the two distinct processes).

These distributions are added in distributions/mixture.py. To do so, I had to move a couple of things around

  • DiracDelta is part of distributions/distribution.py
  • Zero-inflated distributions are now part of distributions/mixture.py
  • These new distributions go into distributions/mixture.py as well
  • Moved tests for DiracDelta and zero-inflated distributions to their respective places

There's a hurdle.ipynb notebook. My goal is not to merge it into the repository (it's in a very bad place). But I think it can be useful if you want to see how these distributions work.

My end goal is to add hurdle families to Bambi and I think it would be better to have these distributions implemented and tested in PyMC rather than as something that only lives within Bambi.

Checklist

New features

  • Added hurdle distributions (HurdlePoisson, HurdleNegativeBinomial, HurdleGamma, and HurdleLogNormal).

Maintenance

  • Move DiracDelta to distributions/distribution.py
  • Move zero-inflated families to distributions/mixture.py
  • Remove pm.Constant

Edit: @ricardoV94

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link
Member

@ricardoV94 ricardoV94 left a comment

Choose a reason for hiding this comment

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

Looks good functionality-wise.

In terms of organization, since there are two things going on, can I ask you to clean the git history and separate the move stuff around and implement hurdle models into two distinct commits?

Comment on lines 1185 to 1199
class Constant:
def __new__(cls, *args, **kwargs):
warnings.warn(
"pm.Constant has been deprecated. Use pm.DiracDelta instead.",
FutureWarning,
)
return DiracDelta(*args, **kwargs)

@classmethod
def dist(cls, *args, **kwargs):
warnings.warn(
"pm.Constant has been deprecated. Use pm.DiracDelta instead.",
FutureWarning,
)
return DiracDelta.dist(*args, **kwargs)
Copy link
Member

@ricardoV94 ricardoV94 Apr 26, 2023

Choose a reason for hiding this comment

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

Good time as any to remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done :)

@codecov
Copy link

codecov bot commented Apr 26, 2023

Codecov Report

Merging #6688 (be27167) into main (fa82fef) will increase coverage by 2.49%.
The diff coverage is 93.61%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6688      +/-   ##
==========================================
+ Coverage   89.50%   91.99%   +2.49%     
==========================================
  Files          94       95       +1     
  Lines       15942    16162     +220     
==========================================
+ Hits        14269    14869     +600     
+ Misses       1673     1293     -380     
Impacted Files Coverage Δ
pymc/distributions/discrete.py 99.11% <ø> (+0.37%) ⬆️
pymc/distributions/mixture.py 94.16% <91.17%> (-1.24%) ⬇️
pymc/distributions/__init__.py 100.00% <100.00%> (ø)
pymc/distributions/distribution.py 96.63% <100.00%> (+0.33%) ⬆️
pymc/logprob/basic.py 99.15% <100.00%> (ø)

... and 13 files with indirect coverage changes

Copy link
Member

@ricardoV94 ricardoV94 left a comment

Choose a reason for hiding this comment

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

We should remove the notebooks (right?)

There seem to be some conflict lines <<<< in the intermediate commits. It probably makes things easier for you to 1) remove Constant, 2) Move things around, 3) Implement the new stuff, in that order.

Let me know if you want me to do it instead.

Everything else 👌

@tomicapretto
Copy link
Contributor Author

There seem to be some conflict lines <<<< in the intermediate commits

I thought they were completely removed. I expected them to be caught by the linting tools. It seems I was wrong.

Let me know if you want me to do it instead.

I would appreciate it a lot :D

@ricardoV94
Copy link
Member

And its correct to remove the notebooks?

@tomicapretto
Copy link
Contributor Author

And its correct to remove the notebooks?

Yes, my bad. It was something I created to see how it worked. But it's not needed.

@tomicapretto tomicapretto force-pushed the hurdle_distributions branch 3 times, most recently from 0ae391c to 47789b8 Compare May 3, 2023 14:01
@ricardoV94 ricardoV94 force-pushed the hurdle_distributions branch from 47789b8 to 8f13b05 Compare May 3, 2023 14:24
@ricardoV94 ricardoV94 force-pushed the hurdle_distributions branch from 8f13b05 to be27167 Compare May 4, 2023 15:01
@ricardoV94 ricardoV94 merged commit a53e865 into pymc-devs:main May 10, 2023
@welcome
Copy link

welcome bot commented May 10, 2023

Congratulations Banner
Congrats on merging your first pull request! 🎉 We here at PyMC are proud of you! 💖 Thank you so much for your contribution 🎁

@tomicapretto tomicapretto deleted the hurdle_distributions branch May 10, 2023 12:11
@ricardoV94 ricardoV94 changed the title Add hurdle distributions Add Hurdle distributions May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants