[SciPy-User] Access to objective function and gradient in minimize callback

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

[SciPy-User] Access to objective function and gradient in minimize callback

Mark vdw
Hi all,

I want to keep track of the optimisation history when using minimize. I want to keep track of the objective function value and the gradient. However, the callback function is only given the current parameters, not the actual value of the objective function and its gradient. So whenever I want to store the current fval and gradient, I have to recompute them in the callback, which is wasteful, especially in the case where I want to store the values at every iteration.

Is there a way to get the fval and gradient that have already been computed inside the optimiser to the callback function?

Many thanks,
Mark

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

Re: Access to objective function and gradient in minimize callback

Daπid
On 18 November 2015 at 15:06, Mark vdw <[hidden email]> wrote:
Is there a way to get the fval and gradient that have already been computed inside the optimiser to the callback function?

This is what I did in a similar scenario: make your objective function a callable class, and on each call save the value and the result. The callback will check if the parameters passed are the same as the last time it was called, and used the cached value.




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

Re: Access to objective function and gradient in minimize callback

Guillaume Gay
In reply to this post by Mark vdw
Hi,

Couldn't you store the associated data during the optimization, as part of the `fun` argument of minimize, which is a function?

Best,

Guilllaume


Le 18/11/2015 15:06, Mark vdw a écrit :
Hi all,

I want to keep track of the optimisation history when using minimize. I want to keep track of the objective function value and the gradient. However, the callback function is only given the current parameters, not the actual value of the objective function and its gradient. So whenever I want to store the current fval and gradient, I have to recompute them in the callback, which is wasteful, especially in the case where I want to store the values at every iteration.

Is there a way to get the fval and gradient that have already been computed inside the optimiser to the callback function?

Many thanks,
Mark


_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/scipy-user

-- 

Guillaume Gay,
Data analysis and modeling in Comutational Biolgy

http://damcb.com

43 rue Horace Bertin
13005 Marseille

+33 953 55 98 89
+33 651 95 94 00

n°SIRET 751 175 233 00020

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

Re: Access to objective function and gradient in minimize callback

Rob Clewley
In reply to this post by Mark vdw
Hi Mark,

On Wed, Nov 18, 2015 at 9:06 AM, Mark vdw <[hidden email]> wrote:
> Is there a way to get the fval and gradient that have already been computed
> inside the optimiser to the callback function?

You basically want a memoized version aka a cache. That's not too
tricky to write yourself but PyDSTool's optimization toolbox package
(mostly code donated by Matthieu Brucher) already does this nicely. It
also keeps a history of all the steps in case you need to do
diagnostics or backtrack.
_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/scipy-user