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
{{ message }}
Repository navigation
BUG: random: np.random.weibull(a=0) sometimes returns inf. #12371
double rk_weibull(rk_state *state, double a)
{
return pow(rk_standard_exponential(state), 1./a);
}
If a is 0, then 1/a is inf. If 0 < r < 1, then r**inf is 0, but if r == 1 then r**inf is 1, and if r > 1 then r**inf is inf. Those are not correct values for this degenerate case of the Weibull distribution. The only value that should be returned by np.random.weibll(a=0) is 0.
This could be fixed by handling a = 0 explicitly, e.g.
double rk_weibull(rk_state *state, double a)
{
if (a == 0) {
return 0.0;
}
return pow(rk_standard_exponential(state), 1./a);
}
(The even edgier edge case of a = -0 is handled before this C code is called.)
Activity
WarrenWeckesser commentedon Nov 12, 2018
Here's the code to generate Weibull variates:
If
ais 0, then1/aisinf. If0 < r < 1, thenr**infis 0, but ifr == 1thenr**infis 1, and ifr > 1thenr**infisinf. Those are not correct values for this degenerate case of the Weibull distribution. The only value that should be returned bynp.random.weibll(a=0)is 0.This could be fixed by handling
a = 0explicitly, e.g.(The even edgier edge case of
a = -0is handled before this C code is called.)BUG: random: Fix handling of a=0 for numpy.random.weibull.
WarrenWeckesser commentedon Nov 12, 2018
Pull request to fix this: #12372
BUG: random: Fix handling of a=0 for numpy.random.weibull.