[SciPy-Dev] `a` and `b` attributes of the stats distributions
Warren Weckesser
warren.weckesser@gmail....
Sun Jul 7 13:36:33 CDT 2013
I've been working on a pull request for one of the distributions in the
stats module, and as often happens, this has lead to the urge to do some
more clean up.
The distributions defined in stats/distributions.py have attributes `a` and
`b` that give the lower and upper ends of the support of the distribution
(i.e. outside of [a, b], the PDF is 0). A problem with this API is that
for many distributions, the support depends on the parameters. Currently,
this is handled in many of the distributions by modifying self.a and self.b
in the _argcheck() method (I guess under the assumption that any method
that needs `a` and `b` will have called `_argcheck()` at some point).
This leads to stateful behavior such as:
In [1]: from scipy.stats import genpareto
In [2]: genpareto.b # Initially b is inf.
Out[2]: inf
In [3]: genpareto.cdf(0, -2)
Out[3]: 0.0
In [4]: genpareto.b # Now b is 0.5 (as a scalar array)
Out[4]: array(0.5)
In [5]: genpareto.cdf(0, 1)
Out[5]: 0.0
In [6]: genpareto.b
Out[6]: array(inf) # b is back to inf, but as a scalar array.
This API is ugly, and I'd like to fix it.
To start, I think there should be a method `_support`:
def _support(self, *args):
"""Returns a tuple (a,b) that gives the support of the
distribution."""
...
All the distributions would be modified to call `self._support(...)` to get
`a` and `b` instead of using the attributes `self.a` and `self.b`. (The
method could be public--I just defaulted to private while working out the
appropriate API.)
It would be nice to get rid of `a` and `b` entirely, but they are currently
public attributes, so I don't think we can simply remove them.
Comments? Suggestions?
Warren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-dev/attachments/20130707/e5cfa61c/attachment.html
More information about the SciPy-Dev
mailing list