covmats.CovViaCholesky#
- class covmats.CovViaCholesky(*args, **kwargs)[source]#
Representation of a covariance via a Cholesky factorization.
- Parameters:
cholesky (array_like) – The lower triangular Cholesky factor of the covariance matrix.
Notes
Let the covariance matrix be \(A\) and \(L\) be the lower Cholesky factor such that \(L L^T = A\). Whitening of a data point \(x\) is performed by computing \(L^{-1} x\). \(\log\det{A}\) is calculated as \(2tr(\log{L})\), where the \(\log\) operation is performed element-wise.
This Covariance class does not support singular covariance matrices because the Cholesky decomposition does not exist for a singular covariance matrix.
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 = rng.random(size=(n, n)) >>> A = A @ A.T # make the covariance symmetric positive definite >>> x = rng.random(size=n)
Perform the Cholesky decomposition of
Aand create the Covariance object.>>> L = np.linalg.cholesky(A) >>> cov = covmats.CovViaCholesky(L)
Compare the functionality of the Covariance object against reference implementation.
>>> from scipy.linalg import solve_triangular >>> res = cov.whiten(x) >>> ref = solve_triangular(L, x, lower=True) >>> np.allclose(res, ref) True >>> res = cov.log_pdet >>> ref = np.linalg.slogdet(A)[-1] >>> np.allclose(res, ref) True
- __init__(L: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], covariance: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] | None = None) None[source]#
Initialize the instance.
- Parameters:
L (NDArrayFloat) – Lower triangle of the covariance matrix Cholesky factorization.
covariance (Optional[NDArrayFloat], optional) – Dense covariance matrix, by default None
Properties
Hermitian adjoint.
Lower triangle of the covariance matrix Cholesky factorization.
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.