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
The beta sampler (beta.rvs) sometimes returns a 1.0 value.
In turn when passed into the beta pdf function (beta.pdf) this 1.0 return an inf values.
Does the 1.0 show up because of some float64 rounding error?
And if so, can I work around this somehow? I need to pass the output of rvs to the pdf as part of some math operations in my code.
The slight over-representation of 1.0 caused by float64 precision rounding (assuming that is the case) is not a problem, but the inf causes many simulations to fail.
In the example above, alpha=1000, beta=0.1, so that as x approaches 1, the PDF is approximately (1-x)**(-0.9), which does indeed approach infinity.
The implementation of beta._rvs(self, a, b) calls self._random_state.beta(a, b, self._size) which appears to be a numpy function to generate the random sample.
If you use
rvs=beta.rvs(0.1,1000,size=20)
then
beta.pdf(rvs,0.1,1000)
will give more accurate versions of the values you would expect from your your original example.
In particular you would be very unlucky to get an inf value.
Basically, you are now generating numbers very close to zero instead of numbers very close to 1. This avoids the (1-x) calculation which due to rounding errors currently delivers 0 rather than someting close to 0.
It appears from the definition that the PDF at x = 1 is indeed inf. (R agrees, if it's any help. dbeta(0, 0.1, 1000)). If I understand correctly, the post was not about the rvs, but if it were, it should probably be reported to NumPy; np.random.beta(1000, 0.1, size=20) gives the same samples.
I don't see a bug, so I'm closing. If I've misunderstood, please reopen @gobbedy. Thanks!
Hello,
The beta sampler (
beta.rvs
) sometimes returns a 1.0 value.In turn when passed into the beta pdf function (
beta.pdf
) this 1.0 return aninf
values.Does the 1.0 show up because of some float64 rounding error?
And if so, can I work around this somehow? I need to pass the output of rvs to the pdf as part of some math operations in my code.
The slight over-representation of 1.0 caused by float64 precision rounding (assuming that is the case) is not a problem, but the inf causes many simulations to fail.
Does the beta distribution support long double?
I would be grateful for any help.
The text was updated successfully, but these errors were encountered: