- qspec.models.fit ( model , x , y , sigma_x = None , sigma_y = None , report = False , routine = None , guess_offset = False , mc_sigma = 0 , ** kwargs )[source]
Fit a
Modelfromqspec.modelsto data. This fit routine encapsulates theqspec.curve_fitand theqspec.odr_fitroutines to facilitate the use of all modular fit model features, such as *Priors* andLinkedfitting.- Parameters:
-
- modelqspec.models._base.Model
The
Modelto fit.- xAny
The input data. Can be any object accepted by the model. If model is a Linked model,
xshould be a list of objects compatible with the linked models.- yndarray | Iterable
The y data. This has to be a 1-d array or a list of 1-d arrays if model is a Linked model.
- sigma_xndarray | Iterable
The uncertainties of the x-values. This is only compatible with Monte-Carlo sampling and the odr_fit routine. If
sigma_xis notNone, no routine is specified andmc_sigma == 0, the routine is automatically set to odr_fit.- sigma_yndarray | Iterable | Callable
The uncertainties of the y-values. This has to be a 1-d array or a list of 1-d arrays if model is a Linked model and have the same shape as
y. If routine iscurve_fit, sigma may be a functiongsuch thatg(x, y, model(x, *params), *params) -> sigma.gshould accept the samexas themodelwhileyandmodel(x, *params)should be 1-d arrays.- reportbool
Whether to print the fit results.
- routineCallable | str
The routine to use for fitting. Currently supported are {'curve_fit', 'odr_fit'}. If
None,curve_fitis used. Seesigma_xfor one exception.- guess_offsetbool
Guess initial parameters for Offset models. Currently, this is not working if
xis not a 1d-array.- mc_sigmaint
The number of samples to generate. If 0, no Monte-Carlo sampling will be done. This is not available with linked fitting.
- kwargsNone
Additional kwargs to pass to the fit
routine.
- Returns:
-
- (popt, pcov, info)(ndarray, ndarray, dict)
The optimized parameters their covariance matrix and a dictionary containing info about the fit.
- Raises:
-
- (ValueError, TypeError)
If the specified routine is not supported (
ValueError) or the specifiedmodelis not aqspec.models.Model(TypeError).