[SciPy-User] computing f and fprime in one evaluation in scipy.optimize
Mon Dec 10 08:54:55 CST 2012
Am 10.12.2012 um 07:23 schrieb ali rahimi:
> When minimizing a function f(x), df/dx can often also be computed with little additional effort. Yet the routines in scipy.optimize accept df/dx as a separate function fprime which must repeat much of the computation of f.
> do the scipy.optimize routines allow me to compute f and fprime simultaneous in one call? this is important to me because each evaluation in my case takes ~10 minutes and a few iterations of the optimizer is all i need.
They are called separately. For a more efficient calculation you could save the result of f, e.g. in a class attribute or a global variable, and reuse it in fprime. And don't forget to also store the parameters to check whether fprime is indeed called with the same params.
More information about the SciPy-User