Lmfit - Minimizer Does Not Accept Scipy Minimizer Keyword Arguments
I am trying to fit some model to my data with lmfit. See the MWE below: import lmfit import numpy as np def lm(params, x): slope = params['slope'] interc = params['interc'
Solution 1:
The best way to pass keyword arguments to the underlying scipy
solver would be just to use
# Note: valid but will not do what you wantfitter = lmfit.Minimizer(lm_min, params, fcn_args=(x, ydata), xatol=0.01)
fit = fitter.minimize(method='nelder')
or
# Also: valid but will not do what you wantfitter = lmfit.Minimizer(lm_min, params, fcn_args=(x, ydata))
fit = fitter.minimize(method='nelder', xatol=0.01)
The main problem here is that xatol
is not a valid keyword argument for the underlying solver, scipy.optimize.minimize()
. Instead, you probably mean to use tol
:
fitter = lmfit.Minimizer(lm_min, params, fcn_args=(x, ydata), tol=0.01)
fit = fitter.minimize(method='nelder')
or
fitter = lmfit.Minimizer(lm_min, params, fcn_args=(x, ydata))
fit = fitter.minimize(method='nelder', tol=0.01)
Solution 2:
In a github issue I found the following solution:
fit = fitter.minimize(method='nelder', **{'options':{'xatol':4e-4}})
Update As mentioned by @dashesy, this is the same as writing:
fit = fitter.minimize(method='nelder', options={'xatol':4e-4})
This also works for other solver options.
Post a Comment for "Lmfit - Minimizer Does Not Accept Scipy Minimizer Keyword Arguments"