-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Refactor several distributions #4640
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
Conversation
fe913df
to
d370008
Compare
@brandonwillard What do you think of my last commit as a solution for the BoundContinuous issue? I moved the BTW I see this was before in the metaclass: https://github.com/pymc-devs/pymc3/blob/1e4163339f963d9728d0160e74d594f685d76b92/pymc3/distributions/distribution.py#L112-L120 Should we move it there or remove those commented lines? |
1433432
to
2d6ef7c
Compare
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.
We don't want to start adding variables at the class level unnecessarily; instead, each class that wants to use an interval
transform should just create its own in Distribution.__new__
. That approach is class-level enough to accomplish the same thing, and it makes the transform-setup logic a little less spread out.
196bb13
to
27ff7b7
Compare
d75d17c
to
d0ee690
Compare
d0ee690
to
c5db0e5
Compare
|
68f4ef2
to
6940e74
Compare
Yeah, it's using this |
6940e74
to
d52ae50
Compare
I added a skipif for the betabinomial test in case we are using scipy < 1.4.0 (which happens in the pytest workflow). The tests should still be covered in the arviz-compat workflow so it should be fine for now. |
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.
Aside from renaming that transform field, it looks like test_distributions_random
could be introducing a significant amount of testing redundancy. Regardless, we can merge this once the transform field name is updated.
pymc3/distributions/continuous.py
Outdated
class BoundedContinuous(Continuous): | ||
"""Base class for bounded continuous distributions""" | ||
|
||
transform_args = None |
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.
Since this field is very specific to upper and lower bounds, its name should reflect that. Currently, it seems like this field specifies which arguments are to be transformed, which is very misleading. Also, the values in this field are argument indices, so that should be made clearer somehow (e.g. upper_lower_bound_indices
, trans_ul_bound_indices
, etc.).
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.
Renamed to bound_args_indices
@@ -2646,6 +2641,18 @@ def __init__(self, nu, *args, **kwargs): | |||
super().__init__(alpha=nu / 2.0, beta=0.5, *args, **kwargs) | |||
|
|||
|
|||
# TODO: Remove this once logpt for multiplication is working! |
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.
Let's create an issue specifically for this before/after merging.
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.
Done: #4683
97fb43f
to
104106b
Compare
pymc3/distributions/continuous.py
Outdated
""" | ||
Draw random values from Triangular distribution. | ||
rv_op = triangular | ||
bound_args_indices = [0, 2] # lower, upper |
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.
Why 2
? And shouldn't these be tuples instead of lists?
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.
Changed to tuples.
The arguments of the triangular RandomOp are in this order (lower, mode, upper)
, and so we need to specify that the first and last are the ones relevant for the transformation, hence (0, 2)
(zero-based index)
|
||
def logp(self, value): | ||
def logp(value, mu, s): |
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.
Why don't we need self
here?
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.
Because these are used only as a sort of static-method by the _logp
dispatcher here: https://github.com/pymc-devs/pymc3/blob/6c247638c506e4b3d6eff86ff24c5e98d34ae055/pymc3/distributions/distribution.py#L96-L102
We are not really using distribution instances anymore IIUC.
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.
What a curious pattern, thanks for explaining.
104106b
to
d9f0775
Compare
This gets us a big step closer to merging |
* Refactor several distributions * Fix continuous bounded default transform * Add 32bit xfail to Weibull logp * Add TODO reminder for Weibull * Refactor random tests * Remove tests covered by Aesara * Refactor BetaBinomial * Add skipif for betabinom depending on scipy version * Rename transform_args to bound_args_indices
Couple more of distributions refactored to
v4
. This should cover all the ones that are to be implemented on Aesara, unless I missed something.Depending on what your PR does, here are a few things you might want to address in the description: