leastsquare#

astropy.modeling.statistic.leastsquare(measured_vals, updated_model, weights, *x)[source]#

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

Parameters:
measured_valsndarray or sequence

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

updated_modelModel instance

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

weightsndarray or None

Array of weights to apply to each residual.

*xndarray

Independent variables on which to evaluate the model.

Returns:
resfloat

The sum of least squares.

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.