chi_squared_statistic

simsit.uncertainty_metrics.chi_squared_statistic(residuals, covariance)

Compute chi-squared statistics from residual vectors and covariance matrices.

For each residual vector dx and covariance matrix C, this computes

chi2 = dx^T C^-1 dx

Parameters

residualsarray-like of shape (n, m) or (m,)

Residual vectors of dimension m. May be a single residual vector or an array of n residual vectors.

covariancearray-like of shape (n, m, m) or (m, m)

Covariance matrix or matrices corresponding to residuals.

Returns

ndarray or float

Array of chi-squared values, or a scalar if scalar inputs are provided.

Raises

ValueError

If the input shapes are incompatible.

numpy.linalg.LinAlgError

If any covariance matrix is singular.