[SciPy-Dev] discussion of options for vectorized scipy.optimize.zeros.newton

Mark Mikofski bwana.marko at yahoo.com
Sat Mar 10 03:12:56 EST 2018


PR #8357 proposes vectorizing `scipy.optimize.zeros.newton`. Several options have been discussed in the PR, and I would like to get more feedback from the mailing list.  

(1) The vectorized version causes a speed reduction for the scalar case. Benchmarks using tests from `test_zeros.py` show from 3X to 9X slowdown. For example `test_newton` with a scalar runs in 46[us] but as a numpy 1-item array takes 408[us].  

A suggested option was to move the vectorized approach to a private function, to check the inputs in the `newton()`, and call the private vectorized version if the input is not scalar. In this case should we just check the initial guess or all of the extra args? IMO we can't know that all of the args are actually used for calculating the objective, although they probably are, so the only value we know will be used is the initial guess. So if implementing this option, I propose only checking the initial guess.  

(2) Halting conditions are also a concern. The current implementation in PR #8357 will raise a RuntimeWarning and return the current guess, if any derivative becomes zero, even though the other items in the array may not have converged.  

A suggested option is to continue to iterate until either all of the derivatives are zero, or the max newton step of the items with a non-zero derivative is less than the specified tolerance. A RuntimeWarning would still be raised if any of the items had a zero derivative, and the message would provide the indices of those items.  

An additional option I considered was to add a flag to allow the user to specify either early or delayed termination in the situation where zero-derivatives exist. Early termination corresponds to the current implementation in PR #8357 (as of 2f2b3df) and delayed corresponds to the option suggested above.  

(3) There may be other issues and options I haven't considered.  

Thanks for your feedback

“As I breath in, I calm my body, as I breath out, I smile” - Thich_Nhat_Hanh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20180310/589b6cf0/attachment.html>


More information about the SciPy-Dev mailing list