endas.cov.DiagonalCovariance

class endas.cov.DiagonalCovariance(diag=None, invdiag=None)

Bases: endas.CovarianceOperator

Implements diagonal covariance matrix.

The covariance operator is internally represented by a sparse matrix. Currently only the main diagonal is supported but other diagonals could be added, if needed. The operator supports all methods of CovarianceOperator. The covariance can be instantiated with either the array of diagonal elements or the reciprocal (inverse) array. This can prevent numerical issues in situations where the inverse coefficients are near zero (thus leading to very large coefficients on the original diagonal) and if only the inverse coefficients are needed (such as when only solve() is called).

Parameters:
  • diag (nx1 array) – Vector of diagonal elements of the covariance matrix. Defines covariance matrix of shape (n, n)
  • invdiag (nx1 array) – Vector of inverse diagonal elements of the covariance matrix. Defines covariance matrix of shape (n, n)

Only one of the diag and invdiag arrays can be given.

diagonal()

Returns the matrix diagonal as an array.

Returns:Array of length self.shape[0] or self.shape[1].
inv_diagonal()

Returns the inverse of the matrix diagonal as an array.

Returns:Array of length self.shape[0] or self.shape[1].