mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-14 19:43:41 +02:00
refactor: Classification of fit method in fits.least_squares simplified,
precision of imiunit solver adjusted, prefitting for alternative methods removed.
This commit is contained in:
parent
e92b1d9e9b
commit
d602bea5b7
1 changed files with 9 additions and 14 deletions
|
@ -96,7 +96,7 @@ def least_squares(x, y, func, priors=None, silent=False, **kwargs):
|
||||||
initial_guess : list
|
initial_guess : list
|
||||||
can provide an initial guess for the input parameters. Relevant for
|
can provide an initial guess for the input parameters. Relevant for
|
||||||
non-linear fits with many parameters.
|
non-linear fits with many parameters.
|
||||||
method : str
|
method : str, optional
|
||||||
can be used to choose an alternative method for the minimization of chisquare.
|
can be used to choose an alternative method for the minimization of chisquare.
|
||||||
The possible methods are the ones which can be used for scipy.optimize.minimize and
|
The possible methods are the ones which can be used for scipy.optimize.minimize and
|
||||||
migrad of iminuit. If no method is specified, Levenberg-Marquard is used.
|
migrad of iminuit. If no method is specified, Levenberg-Marquard is used.
|
||||||
|
@ -487,26 +487,21 @@ def _standard_fit(x, y, func, silent=False, **kwargs):
|
||||||
chisq = anp.sum(((y_f - model) / dy_f) ** 2)
|
chisq = anp.sum(((y_f - model) / dy_f) ** 2)
|
||||||
return chisq
|
return chisq
|
||||||
|
|
||||||
if 'method' in kwargs and not (kwargs.get('method', 'Levenberg-Marquardt') == 'Levenberg-Marquardt'):
|
output.method = kwargs.get('method', 'Levenberg-Marquardt')
|
||||||
output.method = kwargs.get('method')
|
if not silent:
|
||||||
if not silent:
|
print('Method:', output.method)
|
||||||
print('Method:', kwargs.get('method'))
|
|
||||||
if kwargs.get('method') == 'migrad':
|
if output.method != 'Levenberg-Marquardt':
|
||||||
fit_result = iminuit.minimize(chisqfunc, x0)
|
if output.method == 'migrad':
|
||||||
fit_result = iminuit.minimize(chisqfunc, fit_result.x)
|
fit_result = iminuit.minimize(chisqfunc, x0, tol=1e-4) # Stopping crieterion 0.002 * tol * errordef
|
||||||
output.iterations = fit_result.nfev
|
output.iterations = fit_result.nfev
|
||||||
else:
|
else:
|
||||||
fit_result = scipy.optimize.minimize(chisqfunc, x0, method=kwargs.get('method'))
|
fit_result = scipy.optimize.minimize(chisqfunc, x0, method=kwargs.get('method'), tol=1e-12)
|
||||||
fit_result = scipy.optimize.minimize(chisqfunc, fit_result.x, method=kwargs.get('method'), tol=1e-12)
|
|
||||||
output.iterations = fit_result.nit
|
output.iterations = fit_result.nit
|
||||||
|
|
||||||
chisquare = fit_result.fun
|
chisquare = fit_result.fun
|
||||||
|
|
||||||
else:
|
else:
|
||||||
output.method = 'Levenberg-Marquardt'
|
|
||||||
if not silent:
|
|
||||||
print('Method: Levenberg-Marquardt')
|
|
||||||
|
|
||||||
if kwargs.get('correlated_fit') is True:
|
if kwargs.get('correlated_fit') is True:
|
||||||
def chisqfunc_residuals(p):
|
def chisqfunc_residuals(p):
|
||||||
model = func(p, x)
|
model = func(p, x)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue