You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there any interest to have custom termination conditions? This could be implemented with a user-provided callback (procedure pointer). If nothing else it could be useful for comparison with other root-finders in terms of speed or number of function evaluations needed for a given accuracy.
Below is a summary of what the other libraries have (in addition to the classic maximum iterations criterion).
Boost
The default condition used by Boost is
when the relative distance between a and b is less than four times the machine epsilon for T, or 2^{1-bits}, whichever is the larger. In other words, you set bits to the number of bits of precision you want in the result. The minimal tolerance of four times the machine epsilon of type T is required to ensure that we get back a bracketing interval, since this must clearly be at greater than one epsilon in size. While in theory a maximum distance of twice machine epsilon is possible to achieve, in practice this results in a great deal of "thrashing" given that the function whose root is being found can only ever be accurate to 1 epsilon at best.
To get "maximum" precision you would do something like this:
int digits = std::numeric_limits<T>::digits; // Maximum possible binary digits accuracy for type T.// Some fraction of digits is used to control how accurate to try to make the result.int get_digits = digits - 3; // We have to have a non-zero interval at each step, so// maximum accuracy is digits - 1. But we also have to// allow for inaccuracy in f(x), otherwise the last few// iterations just thrash around.
In Fortran the equivalent would be
real(dp) :: x, f
integer:: get_digits
get_digits =digits(x) -3
Boost also gives the possibility to specify a custom termination functor for the root bracket:
template <classT>
structeps_custom
{
eps_custom();
booloperator()(const T& a, const T& b) const; // user-defined
};
It provides also a few predefined termination condition functors to stop at the nearest integer of the true root, or at the integer ceiling/floor of the true root. I don't really know what is the usage case for these.
SciPy
The methods in Scipy generally use a combination of absolute and relative tolerance with small variations picking the factor multiplying the relative tolerance:
Is there any interest to have custom termination conditions? This could be implemented with a user-provided callback (procedure pointer). If nothing else it could be useful for comparison with other root-finders in terms of speed or number of function evaluations needed for a given accuracy.
Below is a summary of what the other libraries have (in addition to the classic maximum iterations criterion).
Boost
The default condition used by Boost is
To get "maximum" precision you would do something like this:
In Fortran the equivalent would be
Boost also gives the possibility to specify a custom termination functor for the root bracket:
It provides also a few predefined termination condition functors to stop at the nearest integer of the true root, or at the integer ceiling/floor of the true root. I don't really know what is the usage case for these.
SciPy
The methods in Scipy generally use a combination of absolute and relative tolerance with small variations picking the factor multiplying the relative tolerance:
np.isclose(a,b)
which is defined asabsolute(a - b) <= (atol + rtol * absolute(b))
)Roots.jl
GSL
GSL provides three search stopping criteria:
gsl_root_test_interval
-gsl_root_test_delta
-gsl_root_test_residual
-Since the GSL solver uses a reverse-communication interface, a user can easily supply his own stopping condition too.
The text was updated successfully, but these errors were encountered: