Skip to content

Binomial and Poisson Moment #5150

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 4 commits into from
Nov 8, 2021

Conversation

farhanreynaldo
Copy link
Contributor

Add moments and tests for the below distributions as part of #5078:

  • pymc.distributions.continuous.Binomial
  • pymc.distributions.Discrete.Poisson

@farhanreynaldo farhanreynaldo force-pushed the binomial-poisson-moment branch from 7dc703a to cd9f9d1 Compare November 7, 2021 09:14
@codecov
Copy link

codecov bot commented Nov 7, 2021

Codecov Report

Merging #5150 (57789b1) into main (2efedc1) will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5150      +/-   ##
==========================================
+ Coverage   77.86%   77.92%   +0.06%     
==========================================
  Files          88       88              
  Lines       14165    14109      -56     
==========================================
- Hits        11029    10995      -34     
+ Misses       3136     3114      -22     
Impacted Files Coverage Δ
pymc/distributions/discrete.py 99.04% <100.00%> (+0.03%) ⬆️
pymc/tests/models.py 79.13% <0.00%> (-8.64%) ⬇️
pymc/tests/backend_fixtures.py 77.55% <0.00%> (-1.43%) ⬇️
pymc/backends/tracetab.py 100.00% <0.00%> (ø)
pymc/distributions/continuous.py 95.82% <0.00%> (+0.02%) ⬆️
pymc/util.py 75.00% <0.00%> (+0.64%) ⬆️
pymc/backends/ndarray.py 89.38% <0.00%> (+19.25%) ⬆️

@twiecki twiecki mentioned this pull request Nov 7, 2021
51 tasks
@twiecki
Copy link
Member

twiecki commented Nov 7, 2021

@farhanreynaldo Need to resolve conflicts.

@farhanreynaldo
Copy link
Contributor Author

@farhanreynaldo Need to resolve conflicts.

This is my first time having a conflict. Are the following steps correct?

git fetch upstream
git rebase upstream/main

and then accept both changes and push the resolved conflicts?

git commit -m "resolve conflicts"
git push origin <branch-name>

@twiecki
Copy link
Member

twiecki commented Nov 7, 2021

I think during rebasing you just git add, and then you force push.

@@ -570,6 +576,11 @@ def dist(cls, mu, *args, **kwargs):
# mode = intX(at.floor(mu))
Copy link
Member

Choose a reason for hiding this comment

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

Seems like we have a leftover from before. Do you mind removing the commented out code?

Suggested change
# mode = intX(at.floor(mu))

Copy link
Member

Choose a reason for hiding this comment

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

Also note that we used the floor of mu, we should do the same in the new get_moment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is the IntX necessary or should I just include the at.floor?

Copy link
Member

Choose a reason for hiding this comment

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

Not needed either I think

@@ -117,6 +117,12 @@ def dist(cls, n, p, *args, **kwargs):
# mode = at.cast(tround(n * p), self.dtype)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# mode = at.cast(tround(n * p), self.dtype)

Same here, we should remove the old commented out code, and use at.round in the new get_moment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is the at.cast also necessary here?

Copy link
Member

Choose a reason for hiding this comment

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

Not anymore. That's done automatically by the function that calls get_moment

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.

Left a couple of suggestions @farhanreynaldo. Thanks for the PR!

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.

Some suggestions to make the tests more robust

(np.arange(1, 5), (2, 4), np.full((2, 4), np.arange(1, 5))),
],
)
def test_poisson_moment(mu, size, expected):
Copy link
Member

Choose a reason for hiding this comment

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

Some of the test combinations should include non integer values for mu to check the flooring is working as expected

(10, np.arange(1, 6) / 10, (2, 5), np.full((2, 5), np.arange(1, 6))),
],
)
def test_binomial_moment(n, p, size, expected):
Copy link
Member

Choose a reason for hiding this comment

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

Some of the test combinations should have a n*p that is different when rounded and not rounded to make sure it is working as expected

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.

3 participants