relentless.optimize.Tolerance#
- class relentless.optimize.Tolerance(absolute, relative)#
Tolerance for convergence tests.
A tolerance can be used to check if one value is close to another in either an absolute or a relative sense. The test for closeness is based on the NumPy method
numpy.isclose(), which can use both an absolute tolerance \(\varepsilon_{\rm a}\) and a relative tolerance \(\varepsilon_{\rm r}\).A value \(a\) is close to a value \(b\) if and only if:
\[\lvert a-b\rvert\le\varepsilon_{\rm a}+\varepsilon_{\rm r}\lvert b\rvert\]An absolute tolerance can be any non-negative numerical value. A relative tolerance must be a non-negative numerical value between 0 and 1. By setting \(\varepsilon_{\rm r}=0\), only an absolute tolerance test is performed. Similarly, setting \(\varepsilon_{\rm a}=0\) will result in the performance of only a relative tolerance test.
- Parameters:
Methods
isclose(a, b[, key])Check if the two values are equivalent within a tolerance.
Attributes
The absolute tolerance(s).
The relative tolerance(s).
- property absolute#
The absolute tolerance(s). Must be non-negative.
- Type:
- isclose(a, b, key=None)#
Check if the two values are equivalent within a tolerance.
The test is performed using
numpy.isclose().The default
absoluteandrelativetolerances can be overridden based on akey, which can be any valid dictionary key other thanNone. When testing for closeness, if akeyis given, the keyed tolerance will be used if has been specified; otherwise, the default tolerance is used.- Parameters:
- Returns:
Trueif values are close.- Return type:
- Raises:
ValueError – If the absolute tolerance is not non-negative.
ValueError – If the relative tolerance is not between 0 and 1.
- property relative#
The relative tolerance(s). Must be between 0 and 1.
- Type: