Skip to content

Adding Dirichlet moment and tests #5174

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 13, 2021

Conversation

larryshamalama
Copy link
Member

This pull request adds get_moment to the Dirichlet class and corresponding tests.

Regarding tests, my third test fails as I am unsure if I am understanding broadcasting correctly. Hoping to add at least a fourth test upon passing the third one

CC: @ricardoV94

Copy link
Member Author

@larryshamalama larryshamalama left a comment

Choose a reason for hiding this comment

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

Comment on third moment test for pm.Dirichlet

@codecov
Copy link

codecov bot commented Nov 11, 2021

Codecov Report

Merging #5174 (fe40965) into main (275c145) will decrease coverage by 0.03%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5174      +/-   ##
==========================================
- Coverage   78.09%   78.06%   -0.04%     
==========================================
  Files          88       88              
  Lines       14149    14157       +8     
==========================================
+ Hits        11050    11052       +2     
- Misses       3099     3105       +6     
Impacted Files Coverage Δ
pymc/distributions/multivariate.py 71.47% <88.88%> (+0.19%) ⬆️
pymc/distributions/discrete.py 98.28% <0.00%> (-1.15%) ⬇️
pymc/bart/pgbart.py 96.24% <0.00%> (-0.38%) ⬇️

@ricardoV94 ricardoV94 mentioned this pull request Nov 11, 2021
51 tasks
@ricardoV94
Copy link
Member

Looks great Larry! Thanks a lot

@ricardoV94 ricardoV94 merged commit 8d1708a into pymc-devs:main Nov 13, 2021
@ricardoV94
Copy link
Member

Would be great to have your help for some of the other multivariate distributions

norm_constant = at.sum(a, axis=-1)[..., None]
moment = a / norm_constant
if not rv_size_is_none(size):
if isinstance(size, int):
Copy link
Member

@ricardoV94 ricardoV94 Nov 13, 2021

Choose a reason for hiding this comment

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

Actually we may need to revisit this. When size is a number it is still inside a TensorConstant. Not sure what isinstance(size, int) will do. Maybe we should check for size.ndim?

Size may also be a symbolic shape. So the same reasoning applies.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks great Larry! Thanks a lot

As always, thanks to you for all your help.

Should we change isinstance(size, int) to if isinstance(size, int) or size.ndim > 0? Would that be a correct approach?

Copy link
Member

@ricardoV94 ricardoV94 Nov 15, 2021

Choose a reason for hiding this comment

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

I checked again and I think that checks will never evaluate true. Even when size is an integer, it gets converted to a TensorConstant([size]):

size = x.owner.inputs[1]
isinstance(size, int)  # False
size.data  # array([2])

If I remove the isinstance block, all tests still pass

@larryshamalama larryshamalama deleted the dirichlet_moment branch November 13, 2021 16:36
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.

2 participants