[Scipy-tickets] [SciPy] #1726: optimize.line_search does not recompute gfk, causes a crash

SciPy Trac scipy-tickets@scipy....
Wed Sep 5 17:20:42 CDT 2012


#1726: optimize.line_search does not recompute gfk, causes a crash
----------------------------+-----------------------------------------------
 Reporter:  mathnathan      |       Owner:  somebody
     Type:  defect          |      Status:  new     
 Priority:  high            |   Milestone:  0.11.0  
Component:  scipy.optimize  |     Version:  0.10.0  
 Keywords:                  |  
----------------------------+-----------------------------------------------
 The function '''scipy.optimize.line_search''' crashes if the gfk parameter
 is left as 'None'.

 ----

 At line 32 of '''optimize.py''', the function line_search_wolfe2 is
 imported as line_search. Therefore the call to line_search is simply a
 call to line_search_wolfe2.

 {{{
 30   from linesearch import \
 31        line_search_BFGS, line_search_wolfe1, line_search_wolfe2, \
 32        line_search_wolfe2 as line_search
 }}}

 At line 183 of '''linesearch.py''' the function line_search_wolfe2 is
 defined with a default parameter 'gfk=None'.

 {{{
 183   def line_search_wolfe2(f, myfprime, xk, pk, gfk=None, old_fval=None,
 184                         old_old_fval=None, args=(), c1=1e-4, c2=0.9,
 amax=50):
 }}}

 At line 199 the docstring shows gfk as optional, and states that it will
 be recomputed if left as None.

 {{{
 197       gfk : ndarray, optional
 198           Gradient value for x=xk (xk being the current parameter
 199           estimate). Will be recomputed if omitted.
 }}}

 However, from line 229 down to line 251 it is not recomputed and is then
 used in the computation of phi prime on line 252, as 'None'.

 {{{
 183   def line_search_wolfe2(f, myfprime, xk, pk, gfk=None, old_fval=None,
 184                          old_old_fval=None, args=(), c1=1e-4, c2=0.9,
 amax=50):
 185       """Find alpha that satisfies strong Wolfe conditions.
 186
 187       Parameters
 188       ----------
       ...
 197       gfk : ndarray, optional
 198           Gradient value for x=xk (xk being the current parameter
 199           estimate). Will be recomputed if omitted.
       ...
 228       """   <---- End of Docstring
 229       fc = [0]
 230       gc = [0]
 231       gval = [None]
 232
 233       def phi(alpha):
 234           fc[0] += 1
 235           return f(xk + alpha * pk, *args)
 236
 237       if isinstance(myfprime, tuple):
 238           def derphi(alpha):
 239               fc[0] += len(xk)+1
 240               eps = myfprime[1]
 241               fprime = myfprime[0]
 242               newargs = (f,eps) + args
 243               gval[0] = fprime(xk+alpha*pk, *newargs)  # store for
 later use
 244               return np.dot(gval[0], pk)
 245       else:
 246           fprime = myfprime
 247           def derphi(alpha):
 248               gc[0] += 1
 249               gval[0] = fprime(xk+alpha*pk, *args)  # store for later
 use
 250               return np.dot(gval[0], pk)
 251
 252       derphi0 = np.dot(gfk, pk)   <---- This line causes the crash
 }}}

 Which results in the following error

 "''TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'''"

 ----

 '''NOTE:''' The Docstring says that myfprime ''(can be None)''. If
 myfprime is None, and gfk is None, then there is not enough information to
 calculate either the curvature or the Armijo conditions.

 Cheers,

 Nathan Crock

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


More information about the Scipy-tickets mailing list