covariance_matrix_inverse¶
- sofia_redux.toolkit.resampling.covariance_matrix_inverse(amat, phi, error, weights, rank=None)[source]¶
Calculates the inverse covariance matrix inverse of the fit coefficients.
If the least-squares solution to a fit is given as
when , the inverse covariance on the estimated fit coefficients is given as:where
are the number of samples fit, are the lost degrees of freedom,W
are the fitweights
, and is related to theerror
( ) by:Note that during the fitting process, it is common for the inverse of the covariance matrix
to have already been calculated (not factoring in lost degrees of freedom) if inverse variance was included as a weighting factor for the fit. If so, it should be passed in asamat
( ), and the final covariance is simply given by:If
amat
was not calculated, it should be supplied as an array of shape (0, 0) (becausenumba
).- Parameters:
- amatnumpy.ndarray (n_terms, n_terms)
The matrix A as described above. If the shape of amat is set to (0, 0), it will be calculated using the error, weights, and phi terms. This should only be done if A was weighted by both
error
andweights
.- phinumpy.ndarray (n_terms, N)
The polynomial terms for each of the N data samples.
- errornumpy.ndarray (N,)
The 1-sigma errors.
- weightsnumpy.ndarray (N,)
The weighting factor applied to each sample when determining the least squares solution of the fit. Note that this must not factor in any error based weighting. Therefore, in the case of the resampling algorithm, it should refer to the distance weighting factor of each sample from the resampling point, or an array of ones (np.ones(N)) if distance weighting was not applied.
- rankint or float, optional
The matrix rank of
amat
, optionally passed in for speed if pre-calculated.
- Returns:
- inverse_covariancenumpy.ndarray (nterms, nterms)
The covariance matrix inverse of fit coefficients.