-
Notifications
You must be signed in to change notification settings - Fork 47
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
[ENH] Adapter for Scipy Distributions #287
Conversation
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.
Thanks!
This was extremely quick and exactly what I meant! Really nice!
Some comments:
- good idea to have separate discrete/continuous. Currently, the interface indeed is different. There is also the issue of not having pmf in the base class.
- for the time being, I think we can leave the handling of
pmf
andlog_pmf
as you suggest. However, you have certainly noted the missing handling ofpmf
in the base class, and that's why you tried to work around it wiht the second class. I would recommend, could you open an issue on implementing thepmf
in the base class? Not necessarily sth to work on right now, but to keep track of what we still need to do. You could also pick it up later in a separate PR, if you'd like.
- for the time being, I think we can leave the handling of
- what I would do is replace entirely the current
Fisk
andPoisson
distribution implementations with the scipy based one. There is no difference in the logic, only the code is more streamlined through the adapter.- don't worry about delete/replace, the classes were written expressly with the idea in mind to later refactor them to a single adapter. What is important to check that this does not change anything, so is a proper refactor - see below.
- what could be helpful is to add some tests for the adapter class, e.g., take
Fisk
and check its outputs against direct outputs fromscipy
. That way we test that the adapter class is really adapting 1:1, and we can check that "before and after" are the same, for this refactor. - finally, may I suggest to pick one more distribution from
scipy
and add it as anskpro
object? How about a beta distribution, given that it is on the priority list in [ENH] roadmap of probability distributions to implement #22?- with the adapter, it should now be easy to add dozens of distributions with minimal work overhead, by using
scipy
. I would leave this to separate PR. And of course the more exotic properties like energy will not be provided byscipy
.
- with the adapter, it should now be easy to add dozens of distributions with minimal work overhead, by using
- make sure you adhere to code formatting standards, here is a guide how to ensure this locally on your computer: https://www.sktime.net/en/stable/developer_guide/coding_standards.html - this is also requierd for the tests on remote to start.
- you can also test your distributions for interface compliance by using
check_estimator
(fromskpro.utils
)
- you can also test your distributions for interface compliance by using
Sure! I would love to do it I have opened the new issue here #289 Please let me know if you have any feedback for the issue! |
Ahh I see, previously, I was a bit afraid to delete them 😅 Okay, I will replace them! |
I tried to run the test, but it turns out that, after changes, Fisk and Poisson failed the test. I will try to understand the test cases and pytest first as this is also my first time having hands-on on pytest. Also for confirmation, from what I understand, it is better for me to make new test file to compare the result of the scipy adapter (let's say |
That is odd. I thought your tests passed with your added distribution, so renaming and moving them should not have broken the tests. Do you have a good guess for the reason of the failures? I think I found your problem - Further, your type annotations are incorrect, these should be |
Yes, exactly. I would add a new file in |
(I fixed the typo in the |
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.
All looks good, unfortunately the failures are on 3.8, from type annotations, square brackets are not supported. Would you be so kind to remove these? These are internal annotations anyway, in private methods.
(we will drop 3.8 support soon, but only in late May or June)
Sure! Absolutely no problem for me! Thank you for fixing it 😄
Thank you so much for pointing this out! I have removed the type annotations square brackets and the test work fine after that! 😄
I have also added the pytest for scipy adapter class, please let me know if you have any feedback for the test! I also changed the scipy adapter by removing the scipy discrete adapter -> if the method is not supported for the discrete/continuous distribution, then it will return 0 (from what I understand on #229 ). Please let me know if it is correct or not😅😅 |
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.
Thanks - this is great!
In a separate step, we may want to move the "return 0" logic into the BaseDistribution
class, and base it on the tag distribution_type
.
What would be great is adding a new distribution, to check whether it is indeed easy to use this adapter - how about beta? You can do this in another PR based on this one. |
Sure, I would like to do that! |
Reference Issues/PRs
Fixes #227
What does this implement/fix? Explain your changes.
Does your contribution introduce a new dependency? If yes, which one?
no
What should a reviewer concentrate their feedback on?
Did you add any tests for the change?
pip install --editable .[dev,test]
and create a simple driver program to use this new distributionAny other comments?
PR checklist
For all contributions
How to: add yourself to the all-contributors file in the
skpro
root directory (not theCONTRIBUTORS.md
). Common badges:code
- fixing a bug, or adding code logic.doc
- writing or improving documentation or docstrings.bug
- reporting or diagnosing a bug (get this pluscode
if you also fixed the bug in the PR).maintenance
- CI, test framework, release.See here for full badge reference
For new estimators
docs/source/api_reference/taskname.rst
, follow the pattern.Examples
section.python_dependencies
tag and ensureddependency isolation, see the estimator dependencies guide.