[SciPy-user] Questions about scipy.optimize.fmin_cobyla
Mon Jul 16 07:30:39 CDT 2007
> Hi all,
> 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:
> 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?
> 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 ?
I would replace xi and log(xi) by exp(xi) and xi
You can try also free (BSD lic) OpenOpt solver lincher, it should handle
your problem well
from scikits.openopt import NLP
p = NLP(f, x0, lb = zeros(x0.size))
r = p.solve('lincher')
however, currently lincher requires QP solver, and the only one
connected is CVXOPT one, so you should have cvxopt installed (GPL). BTW
cvxopt is capable of solving your problem, it has appropriate NLP solver
Also, take a look at tnc
- afaik it allows to handle lb - ub bounds
> 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?
This will not work with any NLP or Nonsmooth solver, that calls for
this will work for some global solvers like anneal, but they are capable
of small-scaled problems only (nVars up to 10)
> Thanks a lot!
> Xiao Jianfeng
> SciPy-user mailing list
More information about the SciPy-user