LevMarLSQFitter#
- class astropy.modeling.fitting.LevMarLSQFitter(calc_uncertainties=False)[source]#
Bases:
_NonLinearLSQFitter
Levenberg-Marquardt algorithm and least squares statistic.
- Parameters:
- calc_uncertaintiesbool
If the covariance matrix should be computed and set in the fit_info. Default: False
- Attributes:
- fit_info
python:dict
The
scipy.optimize.leastsq
result for the most recent fit (see notes).
- fit_info
Notes
The
fit_info
dictionary contains the values returned byscipy.optimize.leastsq
for the most recent fit, including the values from theinfodict
dictionary it returns. See thescipy.optimize.leastsq
documentation for details on the meaning of these values. Note that thex
return value is not included (as it is instead the parameter values of the returned model). Additionally, one additional element offit_info
is computed whenever a model is fit, with the key ‘param_cov’. The corresponding value is the covariance matrix of the parameters as a 2D numpy array. The order of the matrix elements matches the order of the parameters in the fitted model (i.e., the same order asmodel.param_names
).Attributes Summary
The constraint types supported by this fitter type.
Methods Summary
__call__
(model, x, y[, z, weights, maxiter, ...])Fit data to this model.
objective_function
(fps, *args[, ...])Function to minimize.
Attributes Documentation
- supported_constraints = ['fixed', 'tied', 'bounds']#
The constraint types supported by this fitter type.
Methods Documentation
- __call__(model, x, y, z=None, weights=None, maxiter=100, acc=1e-07, epsilon=np.float64(1.4901161193847656e-08), estimate_jacobian=False, filter_non_finite=False, *, inplace=False)#
Fit data to this model.
- Parameters:
- model
FittableModel
model to fit to x, y, z
- x
array
input coordinates
- y
array
input coordinates
- z
array
, optional input coordinates
- weights
array
, optional Weights for fitting. For data with Gaussian uncertainties, the weights should be 1/sigma.
Changed in version 5.3: Calculate parameter covariances while accounting for
weights
as “absolute” inverse uncertainties. To recover the old behavior, chooseweights=None
.- maxiter
python:int
maximum number of iterations
- acc
python:float
Relative error desired in the approximate solution
- epsilon
python:float
A suitable step length for the forward-difference approximation of the Jacobian (if model.fjac=None). If epsfcn is less than the machine precision, it is assumed that the relative errors in the functions are of the order of the machine precision.
- estimate_jacobianbool
If False (default) and if the model has a fit_deriv method, it will be used. Otherwise the Jacobian will be estimated. If True, the Jacobian will be estimated in any case.
- equivalencies
python:list
orpython:None
, optional, keyword-only List of additional equivalencies that are should be applied in case x, y and/or z have units. Default is None.
- filter_non_finitebool, optional
Whether or not to filter data with non-finite values. Default is False
- inplacebool, optional
If
False
(the default), a copy of the model with the fitted parameters set will be returned. IfTrue
, the returned model will be the same instance as the model passed in, and the parameter values will be changed inplace.
- model
- Returns:
- fitted_model
FittableModel
If
inplace
isFalse
(the default), this is a copy of the input model with parameters set by the fitter. Ifinplace
isTrue
, this is the same model as the input model, with parameters updated to be those set by the fitter.
- fitted_model
- objective_function(fps, *args, fit_param_indices=None)#
Function to minimize.
- Parameters:
- fps
python:list
parameters returned by the fitter
- args
python:list
[model, [weights], [input coordinates]]
- fit_param_indices
python:list
, optional The
fit_param_indices
as returned bymodel_to_fit_params
. This is a list of the parameter indices being fit, so excluding any tied or fixed parameters. This can be passed in to the objective function to prevent it having to be computed on every call. This must be optional as not all fitters support passing kwargs to the objective function.
- fps