-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
ricardoV94
merged 4 commits into
pymc-devs:main
from
farhanreynaldo:binomial-poisson-moment
Nov 8, 2021
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cd9f9d1
add poisson and binomial moment
farhanreynaldo 81d682e
remove commented code, floor and round moment
farhanreynaldo 93fe901
non integer values on mu for robust test
farhanreynaldo 57789b1
different rounded binomial for robust test
farhanreynaldo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
from pymc import Bernoulli, Flat, HalfFlat, Normal, TruncatedNormal, Uniform | ||
from pymc.distributions import ( | ||
Beta, | ||
Binomial, | ||
Cauchy, | ||
Exponential, | ||
Gamma, | ||
|
@@ -14,6 +15,7 @@ | |
Kumaraswamy, | ||
Laplace, | ||
LogNormal, | ||
Poisson, | ||
StudentT, | ||
Weibull, | ||
) | ||
|
@@ -209,7 +211,13 @@ def test_laplace_moment(mu, b, size, expected): | |
(0, 1, 1, None, 0), | ||
(0, np.ones(5), 1, None, np.zeros(5)), | ||
(np.arange(5), 10, np.arange(1, 6), None, np.arange(5)), | ||
(np.arange(5), 10, np.arange(1, 6), (2, 5), np.full((2, 5), np.arange(5))), | ||
( | ||
np.arange(5), | ||
10, | ||
np.arange(1, 6), | ||
(2, 5), | ||
np.full((2, 5), np.arange(5)), | ||
), | ||
], | ||
) | ||
def test_studentt_moment(mu, nu, sigma, size, expected): | ||
|
@@ -318,11 +326,44 @@ def test_gamma_moment(alpha, beta, size, expected): | |
np.arange(1, 6), | ||
np.arange(2, 7), | ||
(2, 5), | ||
np.full((2, 5), np.arange(2, 7) * special.gamma(1 + 1 / np.arange(1, 6))), | ||
np.full( | ||
(2, 5), | ||
np.arange(2, 7) * special.gamma(1 + 1 / np.arange(1, 6)), | ||
), | ||
), | ||
], | ||
) | ||
def test_weibull_moment(alpha, beta, size, expected): | ||
with Model() as model: | ||
Weibull("x", alpha=alpha, beta=beta, size=size) | ||
assert_moment_is_expected(model, expected) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"n, p, size, expected", | ||
[ | ||
(7, 0.7, None, 5), | ||
(7, 0.3, 5, np.full(5, 2)), | ||
(10, np.arange(1, 6) / 10, None, np.arange(1, 6)), | ||
(10, np.arange(1, 6) / 10, (2, 5), np.full((2, 5), np.arange(1, 6))), | ||
], | ||
) | ||
def test_binomial_moment(n, p, size, expected): | ||
with Model() as model: | ||
Binomial("x", n=n, p=p, size=size) | ||
assert_moment_is_expected(model, expected) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"mu, size, expected", | ||
[ | ||
(2.7, None, 2), | ||
(2.3, 5, np.full(5, 2)), | ||
(np.arange(1, 5), None, np.arange(1, 5)), | ||
(np.arange(1, 5), (2, 4), np.full((2, 4), np.arange(1, 5))), | ||
], | ||
) | ||
def test_poisson_moment(mu, size, expected): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
with Model() as model: | ||
Poisson("x", mu=mu, size=size) | ||
assert_moment_is_expected(model, expected) |
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.
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.
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