It can indeed be desirable to return f and f’ (and f’’) in a single call, especially if the additional computation for "f’-while-computing-f" is very small. Not all of the derivative-based methods would necessarily benefit (e.g Homeier’s method which evaluates two f' and one f every iteration), but the base Newton’s method wouldn’t see any additional computation. There is an existing PR https://github.com/scipy/scipy/pull/8890 <https://github.com/scipy/scipy/pull/8890> to add `optimize.root_scalar(f, args=(), method=None, bracket=None, fprime=None, fprime2=None,x0=None, x1=None,xtol=None, rtol=None, maxiter=None,options=None)` This would be a 1-dim analog to match the multi-dimensional `optimize.root()`. The `fprime` argument is either a callable or a Boolean. If it is `True`, then calling `f(x, *args)` is expected to return both f and f’. Similarly if `fprime2` is True, then calling `f(x, *args)` is expected to return f, f’ and f’'. -Paul
On Jun 25, 2018, at 3:12 PM, Andrew Nelson <andyfaff@gmail.com> wrote:
On Mon, Jun 25, 2018 at 10:30 AM, Mark Alexander Mikofski <mikofski@berkeley.edu <mailto:mikofski@berkeley.edu>> wrote:
Would anyone disagree or would anyone be interested in a proposal to allow the derivative to be returned from the user supplied function as an optional second argument in gradient search method like Newton? EG
lambda x,a: (x**3-a, 3*x*"2) newton(f, x0, fprime='f2', args=(a,))
Some simple tests show that this may have a 2X speed in cases where the derivative expression requires the value of the original function call.
The `minimize` function does something like this for the `jac` keyword: "If jac is a Boolean and is True, fun is assumed to return the gradient along with the objective function.". If something like this is desirable, then I suggest that the same minimize pattern is used. _______________________________________________ SciPy-Dev mailing list SciPy-Dev@python.org https://mail.python.org/mailman/listinfo/scipy-dev