calculate_fitting_weights

sofia_redux.toolkit.resampling.calculate_fitting_weights(errors, weights, error_weighting=True)[source]

Calculate the final weighting factor based on errors and other weights.

If error_weighting is applied, the return value is weights / error`^2. Otherwise, simply returns `weights.

Parameters:
errorsnumpy.ndarray (N,)

1-sigma error values to apply to weighting.

weightsnumpy.ndarray (N,)

Other weighting factors, not including any type of error weighting.

error_weightingbool

If False, returns weights, otherwise returns weights / errors^2.

Returns:
fit_weightingnumpy.ndarray (N,)

The final fitting weights.

Notes

The square root of the weight is used in the polynomial system of equations rather than the actual weight due to how the least-squares solution is derived.

For the linear system of equations A.x = B, we are solving (A^T.W.A).C = A^T.W.B, where C are the coefficients we wish to find. If we set X = sqrt(W).A, and Y = sqrt(W).B, this is the same as (X^T.X).C = X^T.Y, which can be solved easily. Another way of thinking about it is that we are minimizing the squared residuals (y - f(x))^2.