-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
[GSoC] Sampling from external libraries for all RVs #19342
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
|
✅ Hi, I am the SymPy bot (v158). I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like:
This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.7. Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
Codecov Report
@@ Coverage Diff @@
## master #19342 +/- ##
=============================================
+ Coverage 75.611% 75.643% +0.031%
=============================================
Files 652 652
Lines 169634 169706 +72
Branches 40032 40058 +26
=============================================
+ Hits 128263 128371 +108
+ Misses 35758 35731 -27
+ Partials 5613 5604 -9 |
|
This implementation works good for every CRV and FRV, I found only two failing examples in DRV:
|
|
I think @Upabjojr 's idea of using adaptors can work. Here's what I think, |
|
Removing currently supported libraries have a downside that, users may have to modify their code a lot. And may be, one library can be having different algorithms(which can be better). So, removal of libraries narrows down use cases for the end user. |
|
Then, the previous implementation looks fine if we think of providing multiple libraries. >>> from sympy.stats import *
>>> N = Normal('N',0,1)
>>> resp=next(sample(N, library='pymc3', size=2))
>>> resp, resp.__class__
(array([0.28739264, 1.0677173 ]), <class 'numpy.ndarray'>)
>>> ress=next(sample(N, library='scipy', size=2))
>>> ress, ress.__class__
(array([-0.10553114, -1.55432616]), <class 'numpy.ndarray'>)
>>> resn=next(sample(N, library='numpy', size=2))
>>> resn, resn.__class__
(array([ 0.94539252, -0.68432651]), <class 'numpy.ndarray'>)Then, the only change I suggest, is to use scipy custom distributions when |
74f5122 to
ec7b823
Compare
|
Well, the problem with current design is that everything is stored in a single sampling class and that makes it a bit hard to maintain. |
|
So need to break into three classes? |
|
Yes, like a base sampler class which decides which one of it's child class should get the task of sampling. |
Yes, Should I? |
|
But then this may break the current API and the meaning of |
|
Let's decide on the return type later on. First improve the design. |
|
I have made a change for CRV, if this looks fine then will make similar to DRV and FRV |
|
I think you can apply the same design for discrete and finite variables. |
|
@czgdp1807 Does this require any further changes? |
|
Will be merged tomorrow. Please express your opinions. |
|
Just as a minor thought... Maybe separating the code into files by the external library used... But that's just a thought, no need to do it. Or maybe better so. |
|
I don't see the point in removing the class inheritance and implementing it manually with a dictionary. Too much added complexity for no clear gain. |
|
@czgdp1807 Looks good to me. |
|
@Upabjojr Is this good to go now? |
|
Can we merge this by tomorrow? |
If you want, yes. |
|
I don't know why but a lot of lines are uncovered, https://codecov.io/gh/sympy/sympy/pull/19342/diff |
|
Hi, I have covered all the lines and for all the RVs in the map. The reason here can be because of dependencies on external libraries, the tests might be skipped, so they are not reaching to their respective files. I observed the same with the CRV pr too earlier. |
|
Will be merged tomorrow. |
|
Let's start discussion of simulating stochastic process, probably using external libraries. |

Sampling from External Libraries of sympy random variables
References to other Issues or PRs
FIxes #19061
Fixes #16942
FIxes #8478
Fixes #6160
FIxes #7358
Brief description of what is fixed or changed
Initially, as decided in #18754, there is some improvement in the design as previously all the external sampling was handled by a single class. Instead, there will be separate classes for each library to avoid load on a single class. Also, this PR completes the whole sampling of stats from external libraries including CRV, FRV, and DRV.
Other comments
Release Notes
ping @czgdp1807 @Upabjojr @jmig5776