solve_inverse_covariance_matrices¶
- sofia_redux.toolkit.resampling.solve_inverse_covariance_matrices(phi, error, residuals, weights, error_weighted_amat=None, rank=None, calculate_error=True, calculate_residual=True, estimate_covariance=False)[source]¶
Inverse covariance matrices on fit coefficients from errors and residuals.
A utility function to calculate the inverse covariance matrices of the fit coefficients (\(c\)) based on the \(1\sigma\) error values of the sample measurements and/or the residuals of the fit \(y - c \cdot \Phi\).
The function used to calculate the error covariance may be either
estimated_covariance_matrix_inverse()orcovariance_matrix_inverse(). However,estimated_covariance_matrix_inverse()will always be used to calculate the covariance matrix derived from residuals.- Parameters:
- phinumpy.ndarray (nterms, N)
The polynomial terms for each of the N samples.
- errornumpy.ndarray (N,)
The 1-sigma error values for each sample.
- residualsnumpy.ndarray (N,)
The residuals of the fit y - c.phi.
- weightsnumpy.ndarray (N,)
The weighting of each sample in the fit.
- error_weighted_amatnumpy.ndarray (nterms, nterms), optional
The matrix \(A = \Phi^T W Var(y) W \Phi\), optionally passed in for speed if pre-calculated.
- rankint or float, optional
The rank of
error_weighted_amat, if provided, and it’s rank was pre-calculated. Otherwise, it will be solved for.- calculate_errorbool, optional
If True, calculate the covariance of the fit coefficients based upon the
errorvalues.- calculate_residualbool, optional
If True, calculate the covariance of the fit coefficients based upon
residualsof the fit.- estimate_covariancebool, optional
If True, calculate the covariance of the fit coefficients from the
errorvalues usingestimated_covariance_matrix_inverse(). Otherwise, usecovariance_matrix_inverse().
- Returns:
- e_inv, r_invnumpy.ndarray, numpy.ndarray
The inverse covariance calculated from
error, and the inverse covariance calculated fromresiduals. Ifcalculate_erroris True, the shape of e_cov will be (nterms, nterms) or (0, 0) otherwise. The same is true forcalculate_residualand r_cov.