-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Bring back distribution moments #5078
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
Comments
Updated the top comment with a list of missing moments and some instructions |
I'll add a PR for pymc.distributions.continuous.Beta as a warmup #5145. Will work on some more if I got this one right! 😄 |
Co-authored-by: Ricardo Vieira <[email protected]>
I'll work on the next 5 distributions on the list. PR here #5147
|
I'll do:
|
I would like to take on:
|
Thanks @farhanreynaldo! |
I'd like to work on HalfStudentT |
Sure go ahead :) |
I have added ChiSquared moment. |
Sure, i'll open one. |
All distributions have been taken. I've just unchecked those that don't yet have a PR open to facilitate tracking in the final stage. |
@Domenico89 Any progress on this? |
@anirudhacharya Any progress on this? |
@ricardoV94 I should have an implementation for it, but I am getting an error for some values of the test parameters for which I haven't managed to figure out the reason yet |
Feel free to open a PR with what you have so far and we will help you there |
I will finish up the tests and raise a PR by tomorrow. |
@ricardoV94 Wishart Distribution documentation says - |
@anirudhacharya No, we don't need that for Wishart. |
@ricardoV94 I am having trouble writing tests for the Is there some example usage of this distribution that I can check out? The documentation did not provide any - https://docs.pymc.io/en/v3/api/distributions/discrete.html?highlight=Weibull#pymc3.distributions.discrete.DiscreteWeibull |
Feel free to open a PR with what you have so far, it will be easier to help you then. I don't know about any examples using the distribution, but the check_logp test gives an indication of some values and parameters that are being tested successfully: pymc/pymc/tests/test_distributions.py Lines 1740 to 1746 in a50b386
|
@anirudhacharya are you still interested in the |
Please put it up for grabs. |
@ricardoV94 The mean looks like an infinite sum. This is a job for |
@zoj613 we are not interested in the exact moments, but just good enough moments to start sampling. It seems the mean is quite a costly computation, so we should pick something else, perhaps the median or the mode? All we care is that the initial point always has a non-zero probability and, provided that, it is in a place with relevant prior mass |
Okay I see. If my math is correct it looks like the median can be computed from the CDF expression as:
where CDF = |
Great! Feel free to open a PR for it |
With #4983 and #5087 finished, it's a good time to bring back moments for our distributions for more stable starting points.
With this we can then do the switch in #5009
We should also update the distribution developer guide to mention the implementation of moments: https://github.com/pymc-devs/pymc/blob/main/docs/source/developer_guide_implementing_distribution.md
How to help?
This PR should give a template on how to implement and test new moments for distributions: https://github.com/pymc-devs/pymc/pull/5087/files
In most cases we should be able to copy the moments we were using in the V3 branch. For example here is what we were doing for the
Beta
pymc/pymc3/distributions/continuous.py
Line 1235 in efbacce
2.1 We used to have multiple moments for some distributions such as
mean
,median
,mode
. We only support one moment now, and probably the "higher-order" one is the most useful (that ismean
>median
>mode
)... You might need to truncate the moment if you are dealing with a discrete distribution.2.2 We left some of these moments commented out inside the distribution
dist
classmethod. Make sure they are removed when you implement them!pymc/pymc/distributions/continuous.py
Lines 538 to 539 in 8f3636d
We have to be careful with
size != None
and broadcasting properly when when some parameters that are not used in themoment
may nevertheless inform about the shape of the distribution. E.g.pm.Normal.dist(mu=0, sigma=np.arange(1, 6))
returns a moment of[mu, mu, mu, mu, mu]
. Again Add tests for distributions moments #5087 should give some template to think about thispymc/pymc/distributions/continuous.py
Lines 546 to 550 in 8f3636d
3.1 In the case where you have to manually broadcast the parameters with each other it's important to add test conditions that would fail if you were not to do that. A straightforward way to do this is to make the used parameter a scalar, the unused one(s) a vector (one at a time) and size
None
Just to keep things uniformish, please add the
get_moment
immediately below thedist
classmethod and beforelogp
orlogcdf
methods.New tests have to be added in
test_distributions_moments.py
. Make sure to test different combinations of size and broadcasting to cover the cases mentioned in point 3.Don't hesitate to ask any questions. You can grab as many distributions to implement moments as you want. Just make sure to write in this issue so that we can keep track of it.
Profit with your new open source KARMA!
The following distributions don't have a moment method implemented:
mode
intest_distributions.py
which should be moved/refactored totest_distributions_moments.py
pymc/pymc/tests/test_distributions.py
Line 2151 in bdd4d19
pymc/pymc/tests/test_distributions.py
Line 2189 in bdd4d19
The text was updated successfully, but these errors were encountered: