-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Refactor DensityDist into v4 #5026
Conversation
Codecov Report
@@ Coverage Diff @@
## main #5026 +/- ##
==========================================
+ Coverage 77.85% 78.31% +0.45%
==========================================
Files 128 129 +1
Lines 24349 24400 +51
==========================================
+ Hits 18958 19108 +150
+ Misses 5391 5292 -99
|
fe844a1
to
8a6b9b3
Compare
ndim_supp = cls.rv_op.ndim_supp | ||
if not hasattr(output.tag, "test_value"): | ||
size = to_tuple(kwargs.get("size", None)) + (1,) * ndim_supp | ||
output.tag.test_value = np.zeros(size, dtype) |
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.
The new initval framework will no longer fall back to the test_value. Furthermore this assignment doesn't have a lot of dimensionality flexibility, for example with symbolic size.
My recommendation is to take out the assignment and also the hack below.
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.
Yes, but the new initial value framework has not been finished, so I’ve used the same hack that Flat and HalfFlat use to get their initial values. I don’t think that this PR should have to wait for the new initial values framework to merge it.
In any case, over the new framework is in place, we could change the default initialisation used by density dist.
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.
I like it 👍
Thanks @lucianopaz! |
Closes #4831
This PR ports
DensityDist
into v4. It creates aDensityDistRV
class andDensityDist
class in a similar way as is done by theSimulator
class. When aDensityDist
is created, it registers thelogp
,logcdf
andget_moment
functions for the associated Op type. TheDensityDistRV
is used to overload therng_fn
from the base class to be able to run the user suppliedrandom
callable with the appropriate signature.Depending on what your PR does, here are a few things you might want to address in the description:
The signature of
DensityDist
is completely different than in v3:observed
. The associatedMultiObservedRV
is no longer used or needed and can be removed in a following PR.logp
is now an optional keyword only argument instead of the first positional argument. If users try to pass it as the first positional argument, they will get an exception that tells them that they are using the old v3 API and should change.logp
is now different, it takes in the distribution parameters as positional arguments. Something similar happens forrandom
.logp
,random
,logcdf
andget_moment
are optional. If they are not passed during construction, the RV will be built, but aNotImplementedError
will be raised when you try to do something likepm.sample
,pm.sample_prior_predictive
orget_moment
.The docstrings were updated and new tests have been added for the different optional methods (except
logcdf
) which behaves in the same way aslogp
. If necessary, it's possible to add tests forlogcdf
too.