- qspec.analyze.curve_fit ( f , x , y , p0 = None , p0_fixed = None , sigma = None , absolute_sigma = False , check_finite = True , bounds = (-inf, inf) , method = None , jac = None , full_output = False , report = False , ** kwargs )[source]
Use non-linear least squares to fit a function, $f$, to data. Assumes
ydata = f(xdata, *params) + eps. This is a reimplementation ofscipy.optimize.curve_fitwith the additional features of fixing parameters withp0_fixedand the option to use the parametersigmadynamically as a functiong(x, y, f(x, *params), *params) -> sigma.- Parameters:
-
- fCallable
The model function $f$ to fit to the data.
- xarray_like | object
The $x$ data.
- yarray_like
The $y$ data.
- p0ndarray | Iterable
A numpy array or an Iterable of the initial guesses for the parameters. Must have at least the same length as the minimum number of parameters required by the function
f. Ifp0isNone, 1 is taken as an initial guess for all non-keyword parameters.- p0_fixedndarray | Iterable
A numpy array or an Iterable of
boolvalues specifying whether to fix a parameter. Must have the same length asp0.- sigmandarray | Iterable | Callable
The $1\sigma$ uncertainty of the
ydata. This can also be a function $g$ such thatg(x, y, f(x, *params), *params) -> sigma.- absolute_sigmabool
Assumes ydata = f(xdata, *params) + eps
- check_finitebool
- bounds(ndarray, ndarray)
- methodstr
- jacCallable | str
See
scipy.optimize.curve_fit. Must not be callable ifsigmais callable.- full_outputbool
- reportbool
Whether to print the result of the fit.
- kwargsNone
- Returns:
-
- (popt, pcov)(ndarray, ndarray, Optional[dict], Optional[str], Optional[int])
The optimal parameters and their covariance matrix. Additional output if
full_output == True. Seescipy.optimize.curve_fit.
- Raises:
-
- (ValueError, RuntimeError, OptimizeWarning)
If either
xorycontain NaNs, or if incompatible options are used. If the least-squares minimization fails. If covariance of the parameters can not be estimated.