Search code examples
pythonscipyminimization

Why my scipy.optimize.minimize fails?


I try with fmin_bfgs to find the local minimum of the absolute function abs(x). The initial point is set to 100.0; the expected answer is 0.0. However, I get:

In [184]: op.fmin_bfgs(lambda x:np.abs(x),100.0)
Warning: Desired error not necessarily achieved due to precision loss.
         Current function value: 100.000000
         Iterations: 0
         Function evaluations: 64
         Gradient evaluations: 20
Out[184]: array([100.0])

Why?


Solution

  • Methods like fmin_bfgs and fmin_slsqp require smooth (continuous derivative) functions in order to provide reliable results. abs(x) has a dicontinuous derivative at its minimum. A method like the Nelder-Mead simplex, which doesn't require continuous derivatives, might provide better results in this case.