Skip to main content
`Ctrl`+`K`

# leastsquare

astropy.modeling.statistic.leastsquare(measured_vals, updated_model, weights, *x)

  Least square statistic, with optional weights, in N-dimensions.

  Parameters:
    measured_vals `ndarray` or python:sequence

      Measured data values. Will be cast to array whose shape must match the array-cast of the evaluated model.

    updated_model `Model` instance

      Model with parameters set by the current iteration of the optimizer. when evaluated on “x”, must return array of shape “measured_vals”

    weights `ndarray` or `python:None`

      Array of weights to apply to each residual.

    *x `ndarray`

      Independent variables on which to evaluate the model.

  Returns:
    res `python:float`

      The sum of least squares.

  See also

  `leastsquare_1d()`
  `leastsquare_2d()`
  `leastsquare_3d()`

  Notes

  Models in `modeling` have broadcasting rules that try to match inputs with outputs with Model shapes. Numpy arrays have flexible broadcasting rules, so mismatched shapes can often be made compatible. To ensure data matches the model we must perform shape comparison and leverage the Numpy arithmetic functions. This can obfuscate arithmetic computation overrides, like with Quantities. Implement a custom statistic for more direct control.