[SciPy-Dev] Warnings raised (from fit in scipy.stats)
Fri Jul 2 12:50:46 CDT 2010
On Fri, Jun 11, 2010 at 12:34 PM, Skipper Seabold <email@example.com> wrote:
> On Fri, Jun 11, 2010 at 1:07 PM, <firstname.lastname@example.org> wrote:
>> On Fri, Jun 11, 2010 at 12:45 PM, Skipper Seabold <email@example.com> wrote:
>>> Since the raising of warning behavior has been changed (I believe), I
>>> have been running into a lot of warnings in my code when say I do
>>> something like
>>> In : from scipy import stats
>>> In : y = [-45, -3, 1, 0, 1, 3]
>>> In : v = stats.norm.pdf(y)/stats.norm.cdf(y)
>>> Warning: invalid value encountered in divide
>>> Sometimes, this is useful to know. Sometimes, though, it's very
>>> disturbing when it's encountered in some kind of iteration or
>>> optimization. I have been using numpy.clip to get around this in my
>>> own code, but when it's buried a bit deeper, it's not quite so simple.
>>> Take this example.
>>> In : import numpy as np
>>> In : np.random.seed(12345)
>>> In : B = 6.0
>>> In : x = np.random.exponential(scale=B, size=5000)
>>> In : from scipy.stats import expon
>>> In : expon.fit(x)
>>> <dozens of warnings clipped>
>>> Out: (0.21874043533906118, 5.7122829778172939)
>>> The fit is achieved by fmin (as far as I know, since disp=0 in the
>>> rv_continuous.fit...), but there are a number of warnings emitted. Is
>>> there any middle ground to be had in these type of situations via
>>> context management perhaps?
>>> Should I file a ticket?
>> Which numpy scipy versions are you using?
>> I don't get any warning with the first example. (numpy 1.4.0)
>> (I cannot run the second example because I have a scipy revision with
>> a broken fit() method)
>> I don't think wrapping functions/methods to turn off warnings is a
>> good option. (many of them are in inner loops for example for random
>> number generation)
> Granted I haven't looked too much into the details of the warnings
> context manager other than using some toy examples once or twice, but
> if you could just suppress them for when the solver is called within a
> function/method then this would do the trick (at least for the ones I
> have been running into, mostly to do with fitting like this or with
> maximum likelihood).
Replying to myself here. For noiseless tests (ie., no floating point
warnings) just do
import numpy as np
More information about the SciPy-Dev