[SciPy-user] Questions about scipy.optimize.fmin_cobyla

fdu.xiaojf at gmail.com fdu.xiaojf at gmail.com
Mon Jul 16 09:02:15 EDT 2007


dmitrey wrote:
> fdu.xiaojf at gmail.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 [14]: a = []
>>
>> In [15]: for i in range(4):
>>      b = lambda : i**2
>>      a.append(b)
>>     ....:
>>     ....:
>>
>> In [18]: for f in a:
>>      print f()
>>     ....:
>>     ....:
>> 9
>> 9
>> 9
>> 9
>>
>> What I want is that every function in list a should print different
>> values. The value of a[0](), a[1](), a[2](), a[3]() should be 0, 1, 4,
>> 9.
>>
>> How to achieve this?
>>   
> if your b[i] are funcs from x, you should use b = lambda x: x **2 (for 
> example)
> 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
> c[i](x)<=0
> 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
     cons.append(f)

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.

Regards




More information about the SciPy-User mailing list