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
BUG: rv_discrete
fails when support is unbounded below
#18564
Comments
I'll keep this in mind when I'm working on the infrastructure this summer. This is now tracked in gh-15928. |
There is already one distribution with unbounded support (all integers) https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.skellam.html https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.dlaplace.html |
aside: docstring for dlaplace is confusing because formula does not correspond to the literature or R packages based on PR #2562 |
Agreed with #18564 (comment)'; there's not an inherent problem with unbounded support. import numpy as np
from scipy import stats
class RV(stats.rv_discrete):
def _pmf(self, k):
return np.tanh(1/2) * np.exp(-abs(k))
rv = RV(a=-np.inf, name='RV', longname='An unbounded discrete random variable')
k = np.arange(-100, 110, 10)
rv.pmf(k)
# array([1.71911093e-44, 3.78659382e-40, 8.34052793e-36, 1.83712353e-31,
# 4.04653386e-27, 8.91308397e-23, 1.96323739e-18, 4.32431813e-14,
# 9.52494453e-10, 2.09800865e-05, 4.62117157e-01, 2.09800865e-05,
# 9.52494453e-10, 4.32431813e-14, 1.96323739e-18, 8.91308397e-23,
# 4.04653386e-27, 1.83712353e-31, 8.34052793e-36, 3.78659382e-40,
# 1.71911093e-44]) The problem is with certain methods, like scipy/scipy/stats/_distn_infrastructure.py Lines 3316 to 3319 in c1ed5ec
The immediate error is that The infrastructure would need a more sophisticated algorithm for handling infinite sums (e.g. like I'd suggest that this can be closed by documenting the limitation in the current infrastructure (and the fact that the support must contain only integers) since the need to handle unbounded distributions is tracked by gh-15928. |
cdf could also add negative numbers, as in same with stats, mean, moments. |
Describe your issue.
I am trying to create a discrete distribution on the integers (both positive and negative). The documentation states that
rv_discrete
takes an "optional" lower bound parametera
. It does not, however, seem to allow for an unbounded distribution.The
rv_discrete
class should support unbounded distributions. I recognize this might be a big project, but in the meantime the documentation should be updated to reflect thata
parameter isn't really optional (an optional in Python allows for the valueNone
). Rather, it has a pre-set default.a
must be bounded, even thoughb
can be unboundedReproducing Code Example
Error message
SciPy/NumPy/Python version and system information
The text was updated successfully, but these errors were encountered: