leastsquare¶
- astropy.modeling.statistic.leastsquare(measured_vals, updated_model, weights, *x)[source]¶
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
orpython:None
Array of weights to apply to each residual.
- *x
ndarray
Independent variables on which to evaluate the model.
- measured_vals
- Returns:
- res
python:float
The sum of least squares.
- res
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.