Skip to content

Add tests for distributions moments #5087

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 1 commit into from
Nov 5, 2021

Conversation

michaelosthege
Copy link
Member

Just checking the CI already.

Do we want to systematically test the moments?
Any ideas how to do that without lots of copy-paste?

Related to #5078

@codecov
Copy link

codecov bot commented Oct 18, 2021

Codecov Report

Merging #5087 (7ddc9d4) into main (05aa247) will decrease coverage by 0.03%.
The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5087      +/-   ##
==========================================
- Coverage   77.81%   77.78%   -0.04%     
==========================================
  Files          87       88       +1     
  Lines       14008    14115     +107     
==========================================
+ Hits        10900    10979      +79     
- Misses       3108     3136      +28     
Impacted Files Coverage Δ
pymc/distributions/distribution.py 94.53% <ø> (-0.03%) ⬇️
pymc/distributions/continuous.py 95.55% <81.48%> (-0.05%) ⬇️
pymc/distributions/discrete.py 99.01% <100.00%> (+0.98%) ⬆️
pymc/distributions/shape_utils.py 98.86% <100.00%> (+0.01%) ⬆️
pymc/backends/ndarray.py 70.12% <0.00%> (-16.86%) ⬇️
pymc/smc/sample_smc.py 83.33% <0.00%> (-2.18%) ⬇️
pymc/bart/bart.py 95.45% <0.00%> (-1.57%) ⬇️
pymc/step_methods/metropolis.py 82.83% <0.00%> (-0.87%) ⬇️
pymc/sampling.py 86.80% <0.00%> (-0.14%) ⬇️
pymc/model.py 83.75% <0.00%> (-0.05%) ⬇️
... and 12 more

@ricardoV94
Copy link
Member

Do we want to systematically test the moments?

Definitely

Any ideas how to do that without lots of copy-paste?

None yet. We should probably test that it respects the RV size, while also working with broadcasted params.

@ricardoV94 ricardoV94 marked this pull request as ready for review October 29, 2021 10:19
@ricardoV94 ricardoV94 changed the title Add moments to TruncatedNormal and HalfNormal Add tests for distributions moments Oct 29, 2021
@ricardoV94 ricardoV94 added the v4 label Oct 29, 2021
assert_moment_is_expected(model, expected)


@pytest.mark.skip(reason="aeppl interval transform fails when both edges are None")
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

@michaelosthege michaelosthege left a comment

Choose a reason for hiding this comment

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

I can't approve it, even though @ricardoV94 did 98 % of the changes.

Fixes some pre-existing moments
Adds moments for HalfNormal and TruncatedNormal distributions
Adds helper rv_size_is_none function
@ricardoV94 ricardoV94 merged commit 8f3636d into pymc-devs:main Nov 5, 2021
@twiecki
Copy link
Member

twiecki commented Nov 5, 2021

Do we still need more moments?

@ricardoV94
Copy link
Member

Do we still need more moments?

Yes, see #5078

@michaelosthege michaelosthege deleted the more-moments branch November 5, 2021 13:32
@@ -828,6 +850,12 @@ def dist(cls, sigma=None, tau=None, sd=None, *args, **kwargs):

return super().dist([0.0, sigma], **kwargs)

def get_moment(rv, size, loc, sigma):
moment = loc + sigma
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a doubt here.

Current implementation: loc + sigma
Wikipedia version: loc + \sqrt{\frac{2}{\pi}}sigma

Copy link
Member

Choose a reason for hiding this comment

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

I think you are right, we should probably be using that. Do you want to open a PR to fix it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, happily :)

Copy link
Member

@ricardoV94 ricardoV94 Nov 8, 2021

Choose a reason for hiding this comment

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

A bit more involved, we should probably also use the truncated normal mean as the moment. We might even be able to simplify the switch statement, if the normal logcdf behaves well with +- infinity values: https://en.wikipedia.org/wiki/Truncated_normal_distribution

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.

4 participants