[SciPy-user] Questions about scipy.optimize.fmin_cobyla
dmitrey
openopt@ukr....
Mon Jul 16 08:18:24 CDT 2007
fdu.xiaojf@gmail.com wrote:
> 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
>
>
so if you have only x >= 0 constraints, it's better to use tnc or
openopt lincher than fmin_cobyla
if you have to use cobyla anyway, try this:
a = []
for i in range(5):
a.append(lambda x: x[i]**2)
x = [1,2,3,4,5]
for i in range(5):
print a[i](x)
1
4
9
16
25
If you will replace xi by exp(xi), don't forget to replace lb[i]=0 by
lb[i]=1
HTH, d
More information about the SciPy-user
mailing list