[SciPy-User] Constrained optimization

Ted To rainexpected@theo...
Thu Aug 23 11:37:40 CDT 2012

On 08/22/2012 05:01 PM, Gael Varoquaux wrote:
> 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,

Worked perfectly!  Many thanks!

More information about the SciPy-User mailing list