-
Notifications
You must be signed in to change notification settings - Fork 0
/
_defaults.py
56 lines (49 loc) · 2.23 KB
/
_defaults.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from dynamic_default_args import dynamic_default_args, named_default
import numpy as np
from ._check_args import _check_stop_cond_args
__all__ = [
'set_default_stop_condition_args',
]
# stop condition args
ETOL = 1e-10
ERTOL = 4 * np.finfo(np.float64).eps
PTOL = 1e-12
PRTOL = 4 * np.finfo(np.float64).eps
MAX_ITER = 200
# derivative approximation args
FINITE_DIFF_STEP = 1e-3
@dynamic_default_args()
def set_default_stop_condition_args(etol=named_default(ETOL=ETOL),
ertol=named_default(ERTOL=ERTOL),
ptol=named_default(PTOL=PTOL),
prtol=named_default(PRTOL=PRTOL),
max_iter=named_default(MAX_ITER=MAX_ITER)):
"""
Check default values for etol, ertol, ptol, prtol, and max_iter.
This function uses default values to be modified as its own inputs,
so None value will be interpreted as disabling the stop condition (set to 0).
Args:
etol (float, optional): Error tolerance, indicating the
desired precision of the root. Defaults to {etol}.
ertol (float, optional): Relative error tolerance.
Defaults to {ertol}.
ptol (float, optional): Precision tolerance, indicating
the minimum change of root approximations or width of
brackets (in bracketing methods) after each iteration.
Defaults to {ptol}.
prtol (float, optional): Relative precision tolerance.
Defaults to {prtol}.
max_iter (int, optional): Maximum number of iterations.
If set to 0, the procedure will run indefinitely until
stopping condition is met. Defaults to {max_iter}.
"""
etol, ertol, ptol, prtol, max_iter = _check_stop_cond_args(etol,
ertol,
ptol,
prtol,
max_iter)
named_default('ETOL').value = etol
named_default('ERTOL').value = ertol
named_default('PTOL').value = ptol
named_default('PRTOL').value = prtol
named_default('MAX_ITER').value = max_iter