-
-
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
asymmetric laplace distribution added #4392
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4392 +/- ##
==========================================
+ Coverage 88.15% 88.17% +0.01%
==========================================
Files 88 88
Lines 14564 14587 +23
==========================================
+ Hits 12839 12862 +23
Misses 1725 1725
|
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 added a few comments. I think you also need tests for the random
method in test_distributions_random.py
Great work @chandan5362! One other minor thing you should do once you fix everything is to run pre-commit to auto-format your code to be in line with the rest of the PyMC3 codebase. You have some information here, in case this is new for you. That addresses the test that is currently failing. |
Hey @ricardoV94 , I have been trying to add unit test for
would you please help me here a little ? |
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.
This looks great so far @chandan5362. Coming to the error message, you can try out the comments below and check if the test passes.
The pymc3_random
function checks if samples from distribution's random method and ref_rand
come from same distribution. We need to have tests to check for shape consistencies as well. You can add a test for this very similar to how Normal distribution is tested here.
Also, you might have already done this, but if not, you should also implement the BaseTest. Here is the code for the Laplace distribution: Something similar should work for your distribution. I think this takes care of testing if random works with different sizes/shapes Edit: This was probably what @Sayam753 was saying. Sorry for the repetition :) |
Thanks a lot @Sayam753 @ricardoV94 , It was really helpful. |
pymc3/tests/test_distributions.py
Outdated
@@ -218,7 +220,12 @@ def build_model(distfam, valuedomain, vardomains, extra_args=None): | |||
distfam("value", shape=valuedomain.shape, transform=None, **vals) | |||
return m | |||
|
|||
|
|||
def laplace_asymmetric_logpdf(value, symmetry,scale = 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.
Is this taken from scipy? If so I would mention that in the doc-string and also add a TODO that it should be removed once scipy adds it.
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.
Is this taken from scipy?
yeah @twiecki , It has been taken from SciPy.
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.
OK cool, then just add those notes.
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.
Also not properly black formatted.
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.
hey @twiecki ,
Wish you a very very Happy New Year.
please do review the PR and let me know if anything is yet to be added or removed.
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 addressed some changes to be made. I need some time to review the maths behind random
method. Meanwhile you can work on the suggestions.
One more thing, you can give a mention of AsymmetricLaplace
distribution in api source continuous.rst. Then we can have this distribution to show up in docs.
There also needs to be mention of Support
, Mean
and Variance
in docstring for consistency.
Also, scipy 1.6.0 has been released a few days ago. It contains the asymmetric laplace distribution. In order to use it in test cases, we have to upgrade PyMC3 requirements. Ping @MarcoGorelli to ask if upgrading scipy
will break anything or not.
pymc3/distributions/continuous.py
Outdated
See also: https://en.wikipedia.org/wiki/Asymmetric_Laplace_distribution | ||
""" | ||
|
||
def __init__(self, b, kappa, testval=0.0, *args, **kwargs): |
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.
PyMC3 base Distribution class already handles testval
that can be passed through kwargs
. So, I think testval
should not be there.
While building str
representation of a distribution/model, PyMC3 inspects all arguments passed in __init__
method. With this way, testval may come up in the representation and can certainly be confusing to someone not familiar with test values.
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.
Okay, Thanks
I will have a look at it.
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.
Once I remove the testval
, unit test outputs an error. I think, testval
should be there. Please have a look at it.
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.
Does something like this at the end of __init__
fix it?
self.mode = mu
Assuming you are already using mu (and have converted it to a tensor_variable)
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.
Interesting. I am curious to know how testval interacts self.mode
.
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 think it uses the mode to define the testval. If the mean or median is provided, one of those is used instead.
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.
This is turning out to be in good shape. The random
, logp
method and their tests need to be updated to also account for mu
parameter.
My suggestion would be to first merge #4374, so that we test on the oldest supported scipy version, and then skip any tests which use a too modern scipy (see that same PR for an example) and run those tests during, say, the arviz-compat job, which uses the latest available versions of dependencies I don't think the requirements should be updated if a feature from scipy is only needed to run the tests |
Last step would be to add this distribution for docs in api source continuous.rst and a mention in RELEASE-NOTES.md |
Great work @chandan5362 🎉 . Thanks @twiecki @ricardoV94 for the helpful review. |
What a great example of a high-quality PR and review! 💪 |
Thanks a lot @ricardoV94 @twiecki @Sayam753 for being helpful and supportive . |
Asymmetric Laplace distribution added for #4351
please do let me know if there are any unnecessary changes or any changes that are yet to be made.