[SciPy-user] fmin_l_bfgs_b problem

Travis Oliphant oliphant at ee.byu.edu
Mon Aug 16 15:14:01 CDT 2004


bulatov at cs.orst.edu wrote:

>>On Mon, Aug 09, 2004 at 02:39:59AM -0700, bulatov at cs.orst.edu wrote:
>>    
>>
>>>Was anyone able to use fmin_l_bfgs_b optimizer successfully?
>>>      
>>>
>>Well, I wrote the wrapper, so I hope so :-)
>>
>>    
>>
>>>When I run it with the same parameters as the fmin_bfgs example in the
>>>      
>>>
>tutorial,
>  
>
>>>I get the error:
>>>
>>>xopt = fmin_l_bfgs_b(log_likelihood, x0, fprime=log_likelihood_der)
>>>File "C:\Python23\Lib\site-packages\scipy\optimize\lbfgsb.py", line 174, in
>>>      
>>>
>fm
>  
>
>>>in_l_bfgs_bisave, dsave)
>>>error: failed in converting 7th argument `g' of _lbfgsb.setulb to C/Fortran
>>>array
>>>      
>>>
>>>Are you sure log_likelihood_der returns an array (of the same length as
>>>      
>>>
>x0)?
>
>I found the problem :) Log_likelihood_der returned Numarray array instead of
>Numeric array. That happened because I couldn't find "zeros" function in SciPy,
>so I used numarray.zeros to initialize array. When I changed numarray.zeros to
>Numeric.zeros, problem was fixed.
>  
>
scipy.zeros will also work (i.e. you should never have to call 
Numeric).  This is the safest way to go because then you are guaranteed 
that whatever zeros scipy is using (Numeric or numarray) will be consistent.

>For the future...how do I debug these kinds of problems? I looked in lbfgs.pyf,
>but couldn't quite understand why Numeric arrays were required
>  
>
SciPy currently uses only numeric arrays internally.   Now, most 
functions should happily accept any sequence (including Numarray arrays) 
and if they don't then that should be looked at as a bug --- there might 
be lots of this little bugs.


-Travis O.



>Yaroslav
>
>_______________________________________________
>SciPy-user mailing list
>SciPy-user at scipy.net
>http://www.scipy.net/mailman/listinfo/scipy-user
>  
>



More information about the SciPy-user mailing list