[Scipy-tickets] [SciPy] #1558: Bug in fmin_bfgs linesearch

SciPy Trac scipy-tickets@scipy....
Thu Nov 10 13:24:31 CST 2011


#1558: Bug in fmin_bfgs linesearch
----------------------------------+-----------------------------------------
 Reporter:  kelleyh               |       Owner:  somebody   
     Type:  defect                |      Status:  new        
 Priority:  normal                |   Milestone:  Unscheduled
Component:  scipy.optimize        |     Version:  0.9.0      
 Keywords:  fmin_bfgs linesearch  |  
----------------------------------+-----------------------------------------

Old description:

> The fmin_bfgs routine works fine for me in python 2.6, but failed in
> python 2.7 because of a problem with the linesearch. I think the problem
> was created when the linesearch routine was modified to call the
> scipy.optimize.linesearch package. This is the problematic section of the
> fmin_bfgs function code:
>
>     while (gnorm > gtol) and (k < maxiter):
>         pk = -numpy.dot(Hk,gfk)
>         alpha_k, fc, gc, old_fval, old_old_fval, gfkp1 = \
>            linesearch.line_search(f,myfprime,xk,pk,gfk,
>                                   old_fval,old_old_fval)
>         if alpha_k is None:  # line search failed try different one.
>             alpha_k, fc, gc, old_fval, old_old_fval, gfkp1 = \
>                      line_search(f,myfprime,xk,pk,gfk,
>                                  old_fval,old_old_fval)
>             if alpha_k is None:
>                 # This line search also failed to find a better solution.
>                 warnflag = 2
>                 break
>
> If the first linesearch fails, it also resets the variables old_fval and
> old_old_fval, making them equal to each other. It then calls the second
> linesearch with the new values of old_fval and old_old_fval as arguments,
> making the second search fail and the optimization terminate after one
> iteration:
>
> Warning: Desired error not necessarily achieveddue to precision loss
>          Current function value: 140929642.074956
>          Iterations: 0
>          Function evaluations: 7
>          Gradient evaluations: 1
>
> I fixed this problem by copying the fmin_bfgs code into my own program
> and modifying it to the following:
>
>     while (gnorm > gtol) and (k < maxiter):
>         pk = -numpy.dot(Hk,gfk)
>         original_old_fval=old_fval
>         original_old_old_fval=old_old_fval
>         alpha_k, fc, gc, old_fval, old_old_fval, gfkp1 = \
>            linesearch.line_search(f,myfprime,xk,pk,gfk,
>                                   old_fval,old_old_fval)
>         if alpha_k is None:  # line search failed try different one.
>             alpha_k, fc, gc, original_old_fval, original_old_old_fval,
> gfkp1 = \
>                      line_search(f,myfprime,xk,pk,gfk,
>                                  old_fval,old_old_fval)

New description:

 The fmin_bfgs routine works fine for me in python 2.6, but failed in
 python 2.7 because of a problem with the linesearch. I think the problem
 was created when the linesearch routine was modified to call the
 scipy.optimize.linesearch package. This is the problematic section of the
 fmin_bfgs function code:
 {{{
     while (gnorm > gtol) and (k < maxiter):
         pk = -numpy.dot(Hk,gfk)
         alpha_k, fc, gc, old_fval, old_old_fval, gfkp1 = \
            linesearch.line_search(f,myfprime,xk,pk,gfk,
                                   old_fval,old_old_fval)
         if alpha_k is None:  # line search failed try different one.
             alpha_k, fc, gc, old_fval, old_old_fval, gfkp1 = \
                      line_search(f,myfprime,xk,pk,gfk,
                                  old_fval,old_old_fval)
             if alpha_k is None:
                 # This line search also failed to find a better solution.
                 warnflag = 2
                 break
 }}}
 If the first linesearch fails, it also resets the variables old_fval and
 old_old_fval, making them equal to each other. It then calls the second
 linesearch with the new values of old_fval and old_old_fval as arguments,
 making the second search fail and the optimization terminate after one
 iteration:
 {{{
 Warning: Desired error not necessarily achieveddue to precision loss
          Current function value: 140929642.074956
          Iterations: 0
          Function evaluations: 7
          Gradient evaluations: 1
 }}}
 I fixed this problem by copying the fmin_bfgs code into my own program and
 modifying it to the following:
 {{{
     while (gnorm > gtol) and (k < maxiter):
         pk = -numpy.dot(Hk,gfk)
         original_old_fval=old_fval
         original_old_old_fval=old_old_fval
         alpha_k, fc, gc, old_fval, old_old_fval, gfkp1 = \
            linesearch.line_search(f,myfprime,xk,pk,gfk,
                                   old_fval,old_old_fval)
         if alpha_k is None:  # line search failed try different one.
             alpha_k, fc, gc, original_old_fval, original_old_old_fval,
 gfkp1 = \
                      line_search(f,myfprime,xk,pk,gfk,
                                  old_fval,old_old_fval)
 }}}

--

Comment(by rgommers):

 You have to be a bit more specific here.  What scipy version do you use
 with 2.6 and 2.7? Who modified the linesearch code, and why? Finally, can
 you please provide a self-contained example demonstrating the issue?

 <reformatted description>

-- 
Ticket URL: <http://projects.scipy.org/scipy/ticket/1558#comment:3>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list