[SciPy-Dev] optimize: what should happen if objective functions return non-finite numbers?

Andrew Nelson andyfaff at gmail.com
Wed Jun 15 23:29:49 EDT 2016


On 16 June 2016 at 04:53, Pauli Virtanen <pav at iki.fi> wrote:

> Wed, 15 Jun 2016 09:19:45 +1000, Andrew Nelson kirjoitti:
> > Consider the following example which raises an AssertionError:
> >
> > import numpy as np from scipy.optimize import minimize
> > def func1(x):
> >     return np.nan
> > x0 = np.array([1.3, 0.7, 0.8, 1.9, 1.2])
> > res = minimize(func1, x0, method='l-bfgs-b')
> > assert(res.success = False)
>
> <SNIP>
>


> Whether the optimizer can continue, depends on the method. If it cannot,
> it should return with success=False, and an appropriate error message set.
>
> > minimize simply returns the starting values of: res.x == x0. The reason
> > I came up with this example is that unsanitised datasets sometimes
> > contain nan or inf. Thus, if func1 was calculating chi2 and you were
> > using minimize then the entire fit would appear to succeed (res.success
> > is True), but the output would be garbage.
>
> Why would res.success be true? If it is true when it is clear local
> minimum is not reached, that is a bug.


In the example above res.success is True. On further inspection both
'L-BFGS-B' and 'CG' give res.success is True, the rest give res.success is
False. It's interesting that when I try this with 'COBYLA', then the
minimize function never returns.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20160616/7cf01de8/attachment.html>


More information about the SciPy-Dev mailing list