[SciPy-User] Constrained optimization

Gael Varoquaux gael.varoquaux@normalesup....
Wed Aug 22 16:01:41 CDT 2012


On Wed, Aug 22, 2012 at 04:53:14PM -0400, Ted To wrote:
> The documentation for the constrained optimization routines seems pretty
> sparse and the googling I did revealed nothing in the way of examples of
> usage.  I defined a function W(q) where q is a vector of length 2.
> Using fmin obviously fails (too many iterations) but works in the sense
> that it doesn't outright fail with an error.  Using one of the
> constrained optimizers, fmin_l_bfgs_b for example, completely chokes
> with the Traceback output at http://pastebin.com/t8tU8YBm.  The commands
> leading to this are:

> x0=[.1,.1]
> fmin_l_bfgs_b(W,x0,bounds=[(0,1),(0,1)])

I think that your problem is simply one of reading more carefully the
documentation for fmin_l_bfgs_b: if your function 'W' does not return
both the value of the function and of the gradient, and if you do not
specify the gradient, you must specify approx_grad=1.

Hope this helps,

Gael


More information about the SciPy-User mailing list