Using Scipy.Optimize.Minimize efficiently when compting gradient requires function evaluation
You can pass a callable to the jac argument and it will be used to compute the gradient, while fun will still be called to compute the function value.
so i want to use scipy to minimize a function. In my application i am required to do a function evaluation every time the gradient is required.
I undersand that i can pass a function that will return both, functionvalue and gradient, when i set the arg jac=True. However, sometimes i assume that this procedure will compute gradients when they are not required, e.g. for linesearch, which is very expensive. Is there any way to pass an argument to evaluate the function and an argument to evaluate function and gradient?
EDIT:
i also dont want do compute gradient and functionvalue independently by passing fun and jac since then the fun evaluation inside of jac is often wasted.