Skip to main content
`Ctrl`+`K`

# FittingWithOutlierRemoval

class astropy.modeling.fitting.FittingWithOutlierRemoval(fitter, outlier_func, niter=3, **outlier_kwargs)

  Bases: `object`

  This class combines an outlier removal technique with a fitting procedure. Basically, given a maximum number of iterations `niter`, outliers are removed and fitting is performed for each iteration, until no new outliers are found or `niter` is reached.

  Parameters:
    fitter `Fitter`

      An instance of any Astropy fitter, i.e., LinearLSQFitter, LevMarLSQFitter, SLSQPLSQFitter, SimplexLSQFitter, JointFitter. For model set fitting, this must understand masked input data (as indicated by the fitter class attribute `supports_masked_input`).

    outlier_func `python:callable()`

      A function for outlier removal. If this accepts an `axis` parameter like the `numpy` functions, the appropriate value will be supplied automatically when fitting model sets (unless overridden in `outlier_kwargs`), to find outliers for each model separately; otherwise, the same filtering must be performed in a loop over models, which is almost an order of magnitude slower.

    niter `python:int`, optional

      Maximum number of iterations.

    outlier_kwargs `python:dict`, optional

      Keyword arguments for outlier_func.

  Attributes:
    fit_info `python:dict`

      The `fit_info` (if any) from the last iteration of the wrapped `fitter` during the most recent fit. An entry is also added with the keyword `niter` that records the actual number of fitting iterations performed (as opposed to the user-specified maximum).

  Methods Summary

  `__call__`(model, x, y[, z, weights, inplace]) |

  Methods Documentation

  __call__(model, x, y, z=None, weights=None, *, inplace=False, **kwargs)
    Parameters:
      model `FittableModel`

        An analytic model which will be fit to the provided data. This also contains the initial guess for an optimization algorithm.

      x numpy:array_like

        Input coordinates.

      y numpy:array_like

        Data measurements (1D case) or input coordinates (2D case).

      z numpy:array_like, optional

        Data measurements (2D case).

      weights numpy:array_like, optional

        Weights to be passed to the fitter.

      kwargs `python:dict`, optional

        Keyword arguments to be passed to the fitter.

      inplace bool, optional

        If `False` (the default), a copy of the model with the fitted parameters set will be returned. If `True`, the returned model will be the same instance as the model passed in, and the parameter values will be changed inplace.

    Returns:
      fitted_model `FittableModel`

        If `inplace` is `False` (the default), this is a copy of the input model with parameters set by the fitter. If `inplace` is `True`, this is the same model as the input model, with parameters updated to be those set by the fitter.

      mask `numpy.ndarray`

        Boolean mask array, identifying which points were used in the final fitting iteration (False) and which were found to be outliers or were masked in the input (True).