-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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: stats.trap - adding trapezoidal distribution closes #6028 #6030
Conversation
I noticed that |
Parameters: adding an entry to _distr_params.py runs this battery of tests: https://github.com/scipy/scipy/blob/master/scipy/stats/tests/test_continuous_basic.py#L72 Additional tests (+1 for limiting cases) go to test_distributions.py, which has roughly a test case class per distribution. |
""" | ||
def _rvs(self, c, d): | ||
rands = self._random_state.rand(self._size) | ||
return self._ppf(rands, c, d) |
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 inherited from superclass, not needed here https://github.com/scipy/scipy/blob/master/scipy/stats/_distn_infrastructure.py#L801
You can just define |
x**2 / c / (d - c + 1), | ||
(c + 2 * (x - c)) / (d - c + 1), | ||
1 - ((1 - x)**2 / (d - c + 1) / (1 - d))] | ||
return np.select(condlist, choicelist) |
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.
np.select is cute --- does it handle x, c or d being arrays?
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.
Best solution found so far. It handles x being array or scalar, but c and d have to be scalar.
I had a few mental gymnastics figuring out how to do this without examining if x was array or scalar.
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.
One simple option is of course just two calls to np.where.
@ev-br I added sane values to the trap entry in
|
(As well hidden in the traceback), this is a different set of tests, which generate random sets of parameters: |
also filter out a RuntimeWarning for division by zero in a neighbor test
Out-of-range input is handled automagically by the distributions framework.
You seem to be hitting quite a few ugly corners of the distributions framework... The last remaining failure can be taken care of by just listing I've played with it a bit to check how it fares for array-valued shapes, and it seems OK -- there's an additional simple test in https://github.com/ev-br/scipy/tree/pr/6030, can you take it over? From my POV, this is ready modulo blacklisting the test and renaming it to trapz. |
Conflicts: scipy/stats/tests/test_distributions.py
@@ master #6030 diff @@
======================================
Files 238 238
Stmts 43831 43849 +18
Branches 8215 8215
Methods 0 0
======================================
+ Hit 34262 34280 +18
Partial 2602 2602
Missed 6967 6967
|
Ok, I' m going to merge it. Edge cases, c=0 and d=1, might warrant additional care, but that can be taken care of in a sequel when this sees some usage. Thanks @andyfaff. |
Adds a trapezoidal distribution to
scipy.stats
. For those au-fait with the stats module please inform me of the relevant tests I need to add. The testing framework seems to be automatic, but thetest_stats.py
is mammoth, so I don't know where to start.Possible work to be done (to satisfaction of
stats
guru):_stats
method.