Fitting
The fitting in SpectraFit
is realized by lmifit
and diveded into two parts:
- Minimizer is the class for defining the fitting problem. The sub-dictionary
**args["minimizer"]
can contains all kinds ofkey
andvalue
pairs for setup the Minimizer. - minimizer is the the function of the class Minimizer to perform the optimization. The sub-dictionary
**args["optimizer"]
can contains all kinds ofkey
andvalue
pairs for setup the minimizer.
Python
mini = Minimizer(
solver_model,
params,
fcn_args=(df[args["column"][0]].values, df[args["column"][1]].values),
**args["minimizer"],
)
result = mini.minimize(**args["optimizer"])
About **kwargs
By making use of the ** operator in python
, key-value pairs of a dictionary can be unpacked it into keyword arguments of a function call.
About implemented solvers by LMFIT
All the implemented solvers by LMFIT are listed in the table below:
-
leastsq
: Levenberg-Marquardt (default) -
least_squares
: Least-Squares minimization, using Trust Region Reflective method -
differential_evolution
: differential evolution -
brute
: brute force method -
basinhopping
: basinhopping -
ampgo
: Adaptive Memory Programming for Global Optimization -
nelder
: Nelder-Mead -
lbfgsb
: L-BFGS-B -
powell
: Powell -
cg
: Conjugate-Gradient -
newton
: Newton-CG -
cobyla
: Cobyla -
bfgs
: BFGS -
tnc
: Truncated Newton -
trust-ncg
: Newton-CG trust-region -
trust-exact
: nearly exact trust-region -
trust-krylov
: Newton GLTR trust-region -
trust-constr
: trust-region for constrained optimization -
dogleg
: Dog-leg trust-region -
slsqp
: Sequential Linear Squares Programming -
emcee
: Maximum likelihood via Monte-Carlo Markov Chain -
shgo
: Simplicial Homology Global Optimization -
dual_annealing
: Dual Annealing optimization
Especially, the differential_evolution
is an interesting alternative for solving numerically challenging fitting problems. The method based on this SciPy implementation is implemented in SpectraFit
and can be used by setting the minimizer
parameter to "differential_evolution"
.