[SciPy-user] scipy.optimise.lbfgsb /bounded optimization help

mclaugb mclaughlinbryan at yahoo.com
Sun Jan 28 10:18:26 CST 2007

Thanks, that got me a little further.  I am now getting this error from the 
approx_fprime function in optimize.py :
  File "C:\Python24\lib\site-packages\scipy\optimize\optimize.py", line 577, 
in approx_fprime
    grad[k] = (apply(f,(xk+ei,)+(args)) - f0)/epsilon
ValueError: setting an array element with a sequence.

It appears that args is a tuple rather than type 'numpy.ndarray' like the 
others in the list.  The list of args that i provided to lbfgsb was
args =  numpy.array([GammaMeas.real, GammaMeas.imag, Freq, BeadPerm.real, 
BeadPerm.imag, Inner, Outer])

I could edit the section of code in optimize.py which is causing the error 
at the grad[k] line but not sure that is the correct thing to do.

def approx_fprime(xk,f,epsilon,*args):

    f0 = apply(f,(xk,)+args)
    grad = numpy.zeros((len(xk),), float)
    ei = numpy.zeros((len(xk),), float)
    for k in range(len(xk)):
        ei[k] = epsilon
        grad[k] = (apply(f,(xk+ei,)+(args)) - f0)/epsilon
        ei[k] = 0.0
    return grad

Any thoughts?

"Robert Kern" <robert.kern at gmail.com> wrote in message 
news:45BBE877.9070907 at gmail.com...
> mclaugb wrote:
>> Perhaps that is the problem.  I am using a Windows XP 32-bit system.
> No, I think I found it. Use floats for x0, not integers.
> -- 
> Robert Kern
> "I have come to believe that the whole world is an enigma, a harmless 
> enigma
> that is made terrible by our own mad attempt to interpret it as though it 
> had
> an underlying truth."
>  -- Umberto Eco 

More information about the SciPy-user mailing list