covmats.CovViaDiagonal#
- class covmats.CovViaDiagonal(*args, **kwargs)[source]#
Representation of a covariance matrix via its diagonal.
- Variables:
diagonal (NDArrayFloat) – The diagonal elements of a diagonal matrix.
Notes
Let the diagonal elements of a diagonal covariance matrix \(D\) be stored in the vector \(d\).
When all elements of \(d\) are strictly positive, whitening of a data point \(x\) is performed by computing \(x \cdot d^{-1/2}\), where the inverse square root can be taken element-wise. \(\log\det{D}\) is calculated as \(-2 \sum(\log{d})\), where the \(\log\) operation is performed element-wise.
Notes
No null nor negative elements are allowed, otherwise the matrix would be singular or indefinite and consequently non invertible.
Examples
Prepare a symmetric positive definite covariance matrix
Aand a data pointx.>>> import numpy as np >>> import covmats >>> rng = np.random.default_rng() >>> n = 5 >>> A = np.diag(rng.random(n)) >>> x = rng.random(size=n)
Extract the diagonal from
Aand create the Covariance object.>>> d = np.diag(A) >>> cov = covmats.CovViaDiagonal(d)
Compare the functionality of the Covariance object against a reference implementations.
>>> res = cov.whiten(x) >>> ref = np.diag(d**-0.5) @ x >>> np.allclose(res, ref) True >>> res = cov.log_pdet >>> ref = np.linalg.slogdet(A)[-1] >>> np.allclose(res, ref) True
- __init__(diagonal: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]) None[source]#
Initialize the instance.
- Parameters:
diagonal (ArrayLike) – The diagonal elements of a diagonal matrix.
Properties
1D vector representing the diagonal elements of the covariance matrix.
Hermitian adjoint.
Transpose this linear operator.
Explicit dense representation of the covariance matrix.
Log of the pseudo-determinant of the covariance matrix.
Number of points in the domain (n).
Explicit dense representation of the precision matrix.
Rank of the covariance matrix.
Shape of the covariance matrix (n, n).
Subspace size of the covariance matrix.
Methods
Hermitian adjoint.
Perform a colorizing transformation on data.
Matrix-matrix or matrix-vector multiplication.
Representation of a covariance provided via choleksy factorization.
Representation of a covariance provided via diagonal.
Representation of a covariance provided via eigendecomposition.
Return a representation of a covariance from its precision matrix.
Return the diagonal entries of the matrix (variances).
Return the trace of the covariance matrix (sum of diagonal elements).
Matrix-matrix multiplication.
Matrix-vector multiplication.
Adjoint matrix-matrix multiplication.
Adjoint matrix-vector multiplication.
Draw samples from the multivariate normal N(0, A).
Solve Ax = b, with A, the current covariance matrix instance.
Explicit dense representation of the covariance matrix with shape (n, n).
Transpose this linear operator.
Perform a whitening transformation on data.