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 \(y = \hat{c} \cdot \Phi\) when \(y = c \cdot \Phi + \epsilon\), the inverse covariance on the estimated fit coefficients \(\hat{c}\) is given as:

\[\Sigma^{-1} = \frac{N}{N - M} (\Phi^T W Var(y) \Phi)^{-1}\]

where \(N\) are the number of samples fit, \(M\) are the lost degrees of freedom, W are the fit weights, and \(Var(y)\) is related to the error (\(\sigma\)) by:

\[Var(y) = diag(1 / \sigma^2)\]

Note that during the fitting process, it is common for the inverse of the covariance matrix \(\Sigma\) 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 as amat (\(A\)), and the final covariance is simply given by:

\[\Sigma^{-1} = \frac{N}{N - M}A^{-1}\]

If amat was not calculated, it should be supplied as an array of shape (0, 0) (because numba).

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 and weights.

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.