[SciPy-Dev] "vectorize" scipy.optimize.newton

Mark Mikofski bwana.marko at yahoo.com
Tue Feb 6 23:10:28 EST 2018


I am still looking for reviewers for PR #8357. https://github.com/scipy/scipy/pull/8357
This PR proposes making few minor changes to make scipy.optimize.newton take and return numpy arrays so that users can quickly analyze very large datasets. There are at least two issues regarding this proposal #8354 and  #7242
The pvlib-python package on pypi is using newton to solve the the implicit solar cell model for millions of time intervals and to do Monte Carlo analysis. Looping over newton or using multi-processing is too slow, and a turn off to users, but the vectorised newton method is very fast.
My colleagues and I have also looked at using cython, but the performance of typed native cython functions have not been as fast as using numpy, are more challenging, and more restrictive. Nevertheless we are still pursuing this in a separate effort. My opinion is that users will benefit from both efforts: (1) a ufunc newton and (2) a cython newton that takes a cython typed callback function.
I understand that some are concerned about the tedium of vectorizing and correctly hanging the halting conditions. However there are only a few changes needed for newton because there is no branching*. Simply wrapping the inputs with no.asarray is enough. For halting conditions we look for the max Newton step to be below the tolerance. For division by zero, we look for any derivative that is zero. IMO the proposed code is cleaner, and as a plus it has less lines.
Please consider commenting on the mailing list, on PR 8357, or the related issue 8354
Thanks,Mark MikofskiPrincipal Engineer - Solar ServicesDNV-GL
* The original newton uses the parabolic Halley's method which has a branch if the discriminant is negative. Replacing this with the traditional Halley's method removed this condition and possibly resolved issue 5922. 
 
  On Sat, Feb 3, 2018 at 2:41 PM, Mark Mikofski<bwana.marko at yahoo.com> wrote:   I've submitted a pull request to allow arrays to be used in scipy.optimize.newton:BUG: ENH: vectorize scalar zero-search-functions by mikofski · Pull Request #8357 · scipy/scipy
I would love to hear your comments. Thanks!  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20180207/62b2a41d/attachment.html>


More information about the SciPy-Dev mailing list