ENH: Only use Halley's adjustment to Newton if close enough. #8882
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes gh-8881.
Halley's enhancement to the Newton-Raphson rule divides the step by
(1 - 0.5 * f/f' * f''/f')
If
(1 - 0.5 * f/f' * f''/f')
is not close to 1, then the iteration could easily go in the wrong direction.This only happens when the approximation is not that close. See gh-8881.
Algorithm change: If the denominator
(1 - 0.5 * f/f' * f''/f')
in the adjustment is not close to 1, don't use it, as the current approximation is not close enough to the root to guarantee that the necessary assumptions hold. Just fall-back to a Newton step.Expected changes in behavior in existing usage:
newton(f,...,fprime2=fpp, )
may no longer converge when previously it did. This may occur if the derivative has a zero between the current approximation and the root, or if the sign off'(x0)
andf'(root)
are different. [E.gf(x) = 16*x*(x-1)*(x+1)+7
, which has a single real root-1.17
and is situated on an upward sloping part of the graph. Starting atx0
in a positive but downward sloping part of the graph (say between-0.5 and 0.5
), the algorithm may or may not converge.]I.e. If Newton's algorithm would be on shaky ground due to the presence of stationary points, then using the modification here may change some previous Halley convergences to failures. And vice-versa.