Constrained optimization

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Constrained optimization

zoof
Hi,

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)])

so that the intention is to bound q[0] and q[1] between 0 and 1.

Any help with this would be much appreciated.

Cheers,
Ted
_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: Constrained optimization

Gael Varoquaux
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
_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: Constrained optimization

zoof
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!
_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user