[SciPy-user] Questions about scipy.optimize.fmin_cobyla
Mon Jul 16 08:02:15 CDT 2007
> email@example.com wrote:
>> There are two problems:
>> 1) In the constrain functions, I expected the value of i to be bounded
>> to the specific constrain function, but it doesn't work as I expected.
>> Here is a demonstration:
>> In : a = 
>> In : for i in range(4):
>> b = lambda : i**2
>> In : for f in a:
>> print f()
>> What I want is that every function in list a should print different
>> values. The value of a(), a(), a(), a() should be 0, 1, 4,
>> How to achieve this?
> if your b[i] are funcs from x, you should use b = lambda x: x **2 (for
> however, NLP solvers can't handle these constraints as lb-ub bounds
> (fixed float numbers are required), you should describe them as
> non-linear constraints
> HTH, D.
Yes, b[i] are functions from X, and X is a list.
I want to constrain every xi in X to be larger than 0, so I tried to create
the constrain function like this:
cons = 
for i in range(N): # N is the length of X, or the number of variables
f = lambda x: x[i] - 1e-10
But it didn't work as expected :(
According to the demands of fmin_cobyla, the parameter of cons should be a
list of functions that all must be >=0.
More information about the SciPy-user