[SciPy-User] using scipy.optimize.fmin_slsqp and setting bounds=(None, None)

203 views
Skip to first unread message

Peter Halverson

unread,
Oct 19, 2009, 5:46:27 PM10/19/09
to scipy...@scipy.org
I'm not sure if this is user error or an actual bug. When I attempt to set my bounds in fmin_slsqp the option bounds =[(-10,10),(0,None)] is not recognized Scipy crashes with

IndexError                                Traceback (most recent call last)

C:\Documents and Settings\All Users\Documents\Python\<ipython console> in <module>()

C:\Python25\lib\site-packages\scipy\optimize\slsqp.pyc in fmin_slsqp(func, x0, eqcons, f_eqcons, ieqcons, f_ieqcons, bounds, fprime, fprime_eqcons, fprime_ieqcons, args, iter, acc, iprint, full_output, epsilon)
    244             if bounds[i][0] > bounds[i][1]:
    245                 raise ValueError, \
--> 246                 'SLSQP Error: lb > ub in bounds[' + str(i) +']  ' + str(bounds[4])
    247
    248     xl = array( [ b[0] for b in bounds ] )

IndexError: list index out of range

My code:

import numpy as np
import scipy as sp
from scipy.optimize import fmin_slsqp as fmincon

#The purpose of this script is
# minimize x0+x1^2
# where a and b are constants
# and 0<x0
# and x1-x2>0

def fitfun(x):
    t=x[0]+x[1]**2
    return t

def confun(x):
    return (x[0]-x[1])

bnds =[(-10,10),(0,None)]
guess=[0.5,0.5]

fmincon(fitfun,guess,ieqcons=[confun],bounds=bnds)

If this is a bug I will report it to the appropriate places. If its not a bug please help me sort it out.


Robert Kern

unread,
Oct 20, 2009, 1:17:40 AM10/20/09
to SciPy Users List
On Mon, Oct 19, 2009 at 16:46, Peter Halverson
<halvers...@yahoo.com> wrote:
> I'm not sure if this is user error or an actual bug. When I attempt to set
> my bounds in fmin_slsqp the option bounds =[(-10,10),(0,None)] is not
> recognized Scipy crashes with
>
> IndexError                                Traceback (most recent call last)
>
> C:\Documents and Settings\All Users\Documents\Python\<ipython console> in
> <module>()
>
> C:\Python25\lib\site-packages\scipy\optimize\slsqp.pyc in fmin_slsqp(func,
> x0, eqcons, f_eqcons, ieqcons, f_ieqcons, bounds, fprime, fprime_eqcons,
> fprime_ieqcons, args, iter, acc, iprint, full_output, epsilon)
>     244             if bounds[i][0] > bounds[i][1]:
>     245                 raise ValueError, \
> --> 246                 'SLSQP Error: lb > ub in bounds[' + str(i) +']  ' +
> str(bounds[4])
>     247
>     248     xl = array( [ b[0] for b in bounds ] )
>
> IndexError: list index out of range

Bug. A couple of bugs, actually.

--
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
_______________________________________________
SciPy-User mailing list
SciPy...@scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user

josef...@gmail.com

unread,
Oct 20, 2009, 10:13:58 AM10/20/09
to SciPy Users List

I think bounds are just assumed to be finite (``inf`` doesn't work either)

If you set the bounds to a number that is unlikely to be binding,
then it works.

For example, with

bnds =[(-10,10),(0,1000)]

your example and several variations of it with different constraints binding,
that I tried, work without problems.

Josef

Rob Falck

unread,
Oct 31, 2009, 9:02:25 AM10/31/09
to SciPy Users List
I have a fix for this which changes the default bounds from +/- 1E12 to numpy.finfo(float).max and numpy.finfo(float).min.  It also now detects None and inf and replaces them with max or min, depending on whether they are used in the upper or lower bound.  I'll try to get it into the system this weekend.
--
- Rob Falck

Reply all
Reply to author
Forward
0 new messages