[SciPy-dev] fmin_cg bug

Nils Wagner nwagner at iam.uni-stuttgart.de
Mon Apr 24 08:57:39 EDT 2006


Robert Cimrman wrote:
> Hi,
> the little script below revealed a little bug in scipy.optimize.fmin_cg:
>
> before fix:
> Warning: Desired error not necessarily achieved due to precision loss
>           Current function value: 333283335000.000000
>           Iterations: 0
>           Function evaluations: 2
>           Gradient evaluations: 1
> after fix:
> Optimization terminated successfully.
>           Current function value: 0.000000
>           Iterations: 5
>           Function evaluations: 26
>           Gradient evaluations: 26
>
> I dared to commit the (little :) change to SVN.
>
> r.
>
> ---
> import numpy as nm
> import scipy.optimize as opt
>
> def f( x ):
>      return nm.sum( x * x )
>
> def fg( x ):
>      return 2 * x
>
> x0 = nm.arange( 100000, dtype = nm.float64 )
> x = opt.fmin_cg( f, x0, fg )
>
> _______________________________________________
> Scipy-dev mailing list
> Scipy-dev at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-dev
>   
After fix I get

Optimization terminated successfully.
         Current function value: 0.000000
         Iterations: 5
         Function evaluations: 31
         Gradient evaluations: 31
 >>> scipy.__version__
'0.4.9.1879'
 >>> nm.__version__
'0.9.7.2394'
 >>> x
array([  0.00000000e+00,   2.98982049e-13,   5.97964097e-13, ...,
         2.98973079e-08,   2.98976069e-08,   2.98979059e-08])

Is the number of function evaluations a machine-dependent property ?

Nils





More information about the SciPy-Dev mailing list