[SciPy-user] Questions about scipy.optimize.fmin_cobyla
Mon Jul 16 07:18:10 CDT 2007
I'm trying to minimize a function f(X) = f(x1,x2,...,xn) using cobyla.
In my minimization, all variables should be larger than 0, so I define
constraint functions like this:
cons = 
for i in range(n): # n is the number of variables
c =lambda x: x[i] - 1e-10
And then I use fmin_cobyla(func=f, x0=[0.1]*n, cons=cons) to minimize the
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:
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?
2) In function f(X), there are item of log(xi). Although I have
constrained the value of xi in the constrain functions, xi still may be
equal or less than 0 during minimization, then "math domain error"
What should I do ?
My method is when "math domain error" occurred, catch it and set the
return value of f to a very large number. Should this work or not?
Thanks a lot!
More information about the SciPy-user