You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classCustomExpon(rv_continuous):
""""custom exponential distribution with parameter 0.5"""def_pdf(self, x, *args):
ifx<0.:
return0.else:
return.5*np.exp(-.5*x)
custom_expon=CustomExpon(name='custom_expon')
But when I evaluate print custom_expon.mean() I get a number of InterationWarning and the result is 2.0576933609. (The correct answer is 2.)
I have read the issue #6185 and the advice to set range of distributon a=0. is helpful. But are there any other methods to increase the accuracy of integrating?
The text was updated successfully, but these errors were encountered:
This is really an issue of communicating the intent rather then accuracy.
On the technical level, if you do not define a=0, then your distribution is supposed to have the support of (-inf, inf). Then the numerical integration routine tries to evaluate the integral over the this interval, and finds it difficult (which is not too surprising in retrospect,cf #5428).
Now, the framework has a standard way of specifying the support of a distribution, by setting a and b. What you are doing, you're tricking it into believing that you want the support of (-inf, inf), and normalize the PDF for [0, inf].
As an aside, as soon as you do if x < 0, you lose vectorization (try custom_expon.pdf([1, 2, 3])).
Conclusion: setting a=0 is the correct thing to do. I do not believe there is a bug, so I'm closing this ticket. Feel free to keep discussing though (even though usage questions are better asked on StackOverflow or scipy-user mailing list)
I changed a bit code from scipy.stats.rv_continuous documentation to get a custom exponential distribution with parameter
0.5
:But when I evaluate
print custom_expon.mean()
I get a number of InterationWarning and the result is2.0576933609
. (The correct answer is 2.)I have read the issue #6185 and the advice to set range of distributon
a=0.
is helpful. But are there any other methods to increase the accuracy of integrating?The text was updated successfully, but these errors were encountered: