14
14
"""
15
15
from collections import namedtuple
16
16
from copy import deepcopy
17
+ import inspect
17
18
import multiprocessing
18
19
import numbers
19
20
import warnings
20
- import inspect
21
21
22
22
import numpy as np
23
23
from numpy import ndarray , ones_like , sqrt
77
77
# define the namedtuple here so pickle will work with the MinimizerResult
78
78
Candidate = namedtuple ('Candidate' , ['params' , 'score' ])
79
79
80
- MAXEVAL_Warning = """ ignoring `%s` argument to `%s()`. Use `max_nfev` instead."" "
80
+ MAXEVAL_Warning = "ignoring `%s` argument to `%s()`. Use `max_nfev` instead."
81
81
82
82
83
83
def thisfuncname ():
84
- """Return name of calling function"""
84
+ """Return the name of calling function. """
85
85
try :
86
86
return inspect .stack ()[1 ].function
87
87
except AttributeError :
@@ -268,7 +268,7 @@ class MinimizerResult:
268
268
message : str
269
269
Message about fit success.
270
270
call_kws : dict
271
- Dict of keyword arguments sent to underlying solver method .
271
+ Keyword arguments sent to underlying solver.
272
272
ier : int
273
273
Integer error value from :scipydoc:`optimize.leastsq` (`leastsq` only).
274
274
lmdif_message : str
@@ -380,9 +380,9 @@ def _repr_html_(self, show_correl=True, min_correl=0.1):
380
380
class Minimizer :
381
381
"""A general minimizer for curve fitting and optimization."""
382
382
383
- _err_nonparam = ("params must be a minimizer.Parameters() instance or list "
384
- "of Parameters()" )
385
- _err_max_evals = ("Too many function calls (max set to %i)! Use:"
383
+ _err_nonparam = ("params must be a minimizer.Parameters() instance or"
384
+ " list of Parameters()" )
385
+ _err_max_evals = ("Too many function calls (max set to %i)! Use:"
386
386
" minimize(func, params, ..., max_nfev=NNN)"
387
387
" to increase this maximum." )
388
388
@@ -405,9 +405,9 @@ def __init__(self, userfcn, params, fcn_args=None, fcn_kws=None,
405
405
Positional arguments to pass to `userfcn`.
406
406
fcn_kws : dict, optional
407
407
Keyword arguments to pass to `userfcn`.
408
- max_nfev: int or None
409
- Maximum number of function evaluations. The default value will
410
- change with fitting method.
408
+ max_nfev: int or None, optional
409
+ Maximum number of function evaluations ( default is None). The
410
+ default value depends on the fitting method.
411
411
iter_cb : callable, optional
412
412
Function to be called at each fit iteration. This function should
413
413
have the signature::
@@ -509,11 +509,12 @@ def __init__(self, userfcn, params, fcn_args=None, fcn_kws=None,
509
509
self .nan_policy = nan_policy
510
510
511
511
def set_max_nfev (self , max_nfev = None , default_value = 100000 ):
512
- """
513
- Set maximum number of function evaluations, possibly setting
514
- to the provided default_value
512
+ """Set maximum number of function evaluations.
513
+
514
+ If `max_nfev` is None, use the provided ` default_value`.
515
515
516
516
>>> self.set_max_nfev(max_nfev, 1000*(result.nvarys+1))
517
+
517
518
"""
518
519
if max_nfev is not None :
519
520
self .max_nfev = max_nfev
@@ -889,10 +890,10 @@ def scalar_minimize(self, method='Nelder-Mead', params=None, max_nfev=None,
889
890
- 'differential_evolution'
890
891
891
892
params : :class:`~lmfit.parameter.Parameters`, optional
892
- Parameters to use as starting point.
893
- max_nfev: int or None
894
- Maximum number of function evaluations. Defaults to 1000*(nvars+1)
895
- where nvars is the number of variable parameters.
893
+ Parameters to use as starting point.
894
+ max_nfev: int or None, optional
895
+ Maximum number of function evaluations. Defaults to 1000*(nvars+1),
896
+ where nvars is the number of variable parameters.
896
897
**kws : dict, optional
897
898
Minimizer options pass to :scipydoc:`optimize.minimize`.
898
899
@@ -904,7 +905,7 @@ def scalar_minimize(self, method='Nelder-Mead', params=None, max_nfev=None,
904
905
905
906
906
907
.. versionchanged:: 0.9.0
907
- Return value changed to :class:`MinimizerResult`.
908
+ Return value changed to :class:`MinimizerResult`.
908
909
909
910
Notes
910
911
-----
@@ -1490,10 +1491,10 @@ def least_squares(self, params=None, max_nfev=None, **kws):
1490
1491
Parameters
1491
1492
----------
1492
1493
params : :class:`~lmfit.parameter.Parameters`, optional
1493
- Parameters to use as starting point.
1494
- max_nfev: int or None
1495
- Maximum number of function evaluations. Defaults to 1000*(nvars+1)
1496
- where nvars is the number of variable parameters.
1494
+ Parameters to use as starting point.
1495
+ max_nfev: int or None, optional
1496
+ Maximum number of function evaluations. Defaults to 1000*(nvars+1),
1497
+ where nvars is the number of variable parameters.
1497
1498
**kws : dict, optional
1498
1499
Minimizer options to pass to :scipydoc:`optimize.least_squares`.
1499
1500
@@ -1505,7 +1506,7 @@ def least_squares(self, params=None, max_nfev=None, **kws):
1505
1506
1506
1507
1507
1508
.. versionchanged:: 0.9.0
1508
- Return value changed to :class:`MinimizerResult`.
1509
+ Return value changed to :class:`MinimizerResult`.
1509
1510
1510
1511
"""
1511
1512
result = self .prepare_fit (params )
@@ -1595,10 +1596,10 @@ def leastsq(self, params=None, max_nfev=None, **kws):
1595
1596
Parameters
1596
1597
----------
1597
1598
params : :class:`~lmfit.parameter.Parameters`, optional
1598
- Parameters to use as starting point.
1599
- max_nfev: int or None
1600
- Maximum number of function evaluations. Defaults to 2000*(nvars+1)
1601
- where nvars is the number of variable parameters.
1599
+ Parameters to use as starting point.
1600
+ max_nfev: int or None, optional
1601
+ Maximum number of function evaluations. Defaults to 2000*(nvars+1),
1602
+ where nvars is the number of variable parameters.
1602
1603
**kws : dict, optional
1603
1604
Minimizer options to pass to :scipydoc:`optimize.leastsq`.
1604
1605
@@ -1610,7 +1611,7 @@ def leastsq(self, params=None, max_nfev=None, **kws):
1610
1611
1611
1612
1612
1613
.. versionchanged:: 0.9.0
1613
- Return value changed to :class:`MinimizerResult`.
1614
+ Return value changed to :class:`MinimizerResult`.
1614
1615
1615
1616
"""
1616
1617
result = self .prepare_fit (params = params )
@@ -1986,7 +1987,7 @@ def ampgo(self, params=None, max_nfev=None, **kws):
1986
1987
1987
1988
1988
1989
Notes
1989
- ----
1990
+ -----
1990
1991
The Python implementation was written by Andrea Gavana in 2014
1991
1992
(http://infinity77.net/global_optimization/index.html).
1992
1993
@@ -2051,8 +2052,10 @@ def shgo(self, params=None, max_nfev=None, **kws):
2051
2052
params : :class:`~lmfit.parameter.Parameters`, optional
2052
2053
Contains the Parameters for the model. If None, then the
2053
2054
Parameters used to initialize the Minimizer object are used.
2054
- max_nfev: int (default is None)
2055
- Maximum number of total function evaluations.
2055
+ max_nfev: int or None, optional
2056
+ Maximum number of function evaluations. Defaults to
2057
+ 1e6*(result.nvarys+1), where nvars is the number of variable
2058
+ parameters.
2056
2059
**kws : dict, optional
2057
2060
Minimizer options to pass to the SHGO algorithm.
2058
2061
@@ -2121,8 +2124,8 @@ def dual_annealing(self, params=None, max_nfev=None, **kws):
2121
2124
params : :class:`~lmfit.parameter.Parameters`, optional
2122
2125
Contains the Parameters for the model. If None, then the
2123
2126
Parameters used to initialize the Minimizer object are used.
2124
- max_nfev: int or None
2125
- Maximum number of function evaluations. Default is 1e7.
2127
+ max_nfev: int or None, optional
2128
+ Maximum number of function evaluations. Defaults to 1e7.
2126
2129
**kws : dict, optional
2127
2130
Minimizer options to pass to the dual_annealing algorithm.
2128
2131
@@ -2242,7 +2245,7 @@ def minimize(self, method='leastsq', params=None, **kws):
2242
2245
2243
2246
2244
2247
.. versionchanged:: 0.9.0
2245
- Return value changed to :class:`MinimizerResult`.
2248
+ Return value changed to :class:`MinimizerResult`.
2246
2249
2247
2250
"""
2248
2251
function = self .leastsq
@@ -2449,9 +2452,9 @@ def minimize(fcn, params, method='leastsq', args=None, kws=None, iter_cb=None,
2449
2452
Whether to calculate the covariance matrix (default is True) for
2450
2453
solvers other than `leastsq` and `least_squares`. Requires the
2451
2454
`numdifftools` package to be installed.
2452
- max_nfev: int or None
2453
- Maximum number of function evaluations. Default is different for each
2454
- fitting method.
2455
+ max_nfev: int or None, optional
2456
+ Maximum number of function evaluations (default is None). The
2457
+ default value depends on the fitting method.
2455
2458
**fit_kws : dict, optional
2456
2459
Options to pass to the minimizer being used.
2457
2460
0 commit comments