endas.CovarianceOperator¶
-
class
endas.
CovarianceOperator
¶ Bases:
object
Abstract representation of a covariance matrix.
The base class defines interface required by covariance matrix implementations. See the
endas.cov
module for concrete implementations.-
shape
¶ Returns the shape of the covariance matrix represented by this operator. Since this is a covariance matrix, the shape is always square
-
is_diagonal
¶ Returns
True
if the covariance is represented by a diagonal matrix.The default implementation returns
False
.Note
If True, calling
to_matrix(False)
must return an instance ofscipy.sparse.dia_matrix
, i.e. a sparse matrix in diagonal format.
-
mc_only
¶ Returns
True
if this covariance operator only supports Monte-Carlo sampling via the random_multivariate_normal().The default implementation returns
True
as this is the minimal functionality a covariance operator must support. Implementations that return False will throw NotImplementedError from any method other than random_multivariate_normal().
-
to_matrix
(force_dense=False, out=None)¶ Returns the covariance matrix.
Parameters: - force_dense – If True, the returned matrix is always dense. Otherwise a sparse matrix may be returned, if suitable for the covariance operator.
- out – If specified, the array is used as the output buffer instead of allocating new array. The provided array must have the correct shape.
The default implementation raises NotImplementedError.
Raises: NotImplementedError
– if the operation is not supportedMemoryError
– if the covariance matrix array cannot be allocated
Note
Please note that this should only be used on special cases such as diagonal covariance matrices (see
is_diagonal()
) or for visualization and debugging. The call is likely to run out of memory when use on a large covariance operator.
-
random_multivariate_normal
(N=1)¶ Implements generation of a random sample from multivariate Normal distribution with zero mean and covariance given by this CovarianceMatrix instance.
Parameters: N – The number of independent samples to draw. Returns: nxN array where n is the state space size (i.e. self.shape[0]).
-
solve
(b, overwrite_b=False)¶ Solves the system \(\mathbf{C}x = b\), where \(\mathbf{C}\) is the covariance matrix represented by this
CovarianceOperator
instance.Parameters: b (n x m array) – Data for the right hand side, where n is the size of the covariance matrix and \(m \geq 1\) Returns: The solution x. The shape of the array is equivalent to the shape of b.
-
add_to
(x)¶ Sums this covariance matrix and x and stores the result in x. Please note that this may not be supported by all covariance matrix implementations.
Generally, only covariance matrices that can afford to be represented explicitly (small matrices, diagonal matrices) implement this. In other cases
NotImplementedError
is raised.
-
localize
(selected, taper)¶ Returns new
CovarianceOperator
for a subset of the original operator.The default implementation raises
NotImplementedError
.Parameters: selected – Array of indexes of observations to select Returns: An instance of ObservationOperator
of shape (s, n), wheres = len(selected)
.Raises: NotImplementedError
– if the operation is not supported by this operator
-