[Scipy-tickets] [SciPy] #1788: calling scipy.optimize.minimize with a sparse jacobian fails

SciPy Trac scipy-tickets@scipy....
Tue Dec 11 17:01:33 CST 2012


#1788: calling scipy.optimize.minimize with a sparse jacobian fails
----------------------------+-----------------------------------------------
 Reporter:  furiousd        |       Owner:  dlaxalde   
     Type:  defect          |      Status:  new        
 Priority:  normal          |   Milestone:  Unscheduled
Component:  scipy.optimize  |     Version:  0.11.0     
 Keywords:                  |  
----------------------------+-----------------------------------------------
 When calling scipy.optimize.minimize, inputting a jacobian function that
 returns a sparse matrix (as opposed to a regular array) causes the routine
 to crash when using methods Newton-CG, CG, and BFGS (which all support
 jacobians).

 Environment:
 scipy 0.11.0
 numpy 1.6.2
 Python 2.7.3
 Windows 7

 The relevant portion of the error log when using Newton-CG is:
 {{{
   File "C:\Python27\lib\site-packages\scipy\optimize\_minimize.py", line
 347, in
  minimize
     **options)
   File "C:\Python27\lib\site-packages\scipy\optimize\optimize.py", line
 1252, in
  _minimize_newtoncg
     maggrad = numpy.add.reduce(abs(b))
 TypeError: cannot reduce on a scalar
 }}}

 The relevant portion of the error log when using CG is:
 {{{
   File "C:\Python27\lib\site-packages\scipy\optimize\_minimize.py", line
 342, in
  minimize
     return _minimize_cg(fun, x0, args, jac, callback, **options)
   File "C:\Python27\lib\site-packages\scipy\optimize\optimize.py", line
 1025, in
  _minimize_cg
     old_old_fval, c2=0.4)
   File "C:\Python27\lib\site-packages\scipy\optimize\linesearch.py", line
 93, in
  line_search_wolfe1
     c1=c1, c2=c2, amax=amax, amin=amin, xtol=xtol)
   File "C:\Python27\lib\site-packages\scipy\optimize\linesearch.py", line
 145, i
 n scalar_search_wolfe1
     alpha1 = min(1.0, 1.01*2*(phi0 - old_phi0)/derphi0)
 TypeError: unsupported operand type(s) for /: 'float' and 'csc_matrix'
 }}}

 The relevant portion of the error log when using BFGS is:
 {{{
   File "C:\Python27\lib\site-packages\scipy\optimize\_minimize.py", line
 344, in
  minimize
     return _minimize_bfgs(fun, x0, args, jac, callback, **options)
   File "C:\Python27\lib\site-packages\scipy\optimize\optimize.py", line
 791, in
 _minimize_bfgs
     old_fval, old_old_fval)
   File "C:\Python27\lib\site-packages\scipy\optimize\linesearch.py", line
 93, in
  line_search_wolfe1
     c1=c1, c2=c2, amax=amax, amin=amin, xtol=xtol)
   File "C:\Python27\lib\site-packages\scipy\optimize\linesearch.py", line
 145, i
 n scalar_search_wolfe1
     alpha1 = min(1.0, 1.01*2*(phi0 - old_phi0)/derphi0)
 TypeError: unsupported operand type(s) for /: 'float' and 'csc_matrix'
 }}}

 Given the importance of sparse matrices in minimization routines (and
 jacobians in particular), I think it is essential to support them in this
 usage.

 If needed, I can try to assist with addressing this issue; I have a vested
 interest in seeing it fixed!

 Thanks,
 Dan

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


More information about the Scipy-tickets mailing list