covmats.CovViaSparsePrecisionCholesky#
- class covmats.CovViaSparsePrecisionCholesky(*args, **kwargs)[source]#
Representation of a covariance via the sparse Cholesky factorization of its sparse inverse (aka the precision matrix).
Notes
Let the covariance matrix be \(\mathbf{A}\), its precision matrix be \(\mathbf{Q} = \mathbf{A}^{-1}\), and let \(\mathbf{L}\mathbf{D}\mathbf{L}^{T} = \mathbf{P}\mathbf{Q}\mathbf{P}^{T}\) be the sparse \(\mathbf{L}\mathbf{D}\mathbf{L}^{T}\) factorization of \(\mathbf{Q}\) (see
SparseCholeskyFactor).Products with the covariance matrix and whitening/colorizing operations are obtained by solving sparse triangular systems involving L and D, so that the dense covariance matrix \(\mathbf{A}\) is never built explicitly. This makes this representation well suited to large-scale, sparse precision matrices such as those arising from Markov random fields or SPDE-based Gaussian random fields.
This Covariance class does not support singular covariance/precision matrices because the Cholesky-like factorization does not exist for a singular matrix.
Examples
>>> import numpy as np >>> import scipy as sp >>> import covmats >>> Q = covmats.get_SPD_sparse_n11_example(seed=42) # sparse precision >>> L, D, P = sp.linalg.ldl(Q.toarray()) # dense LDL' for the example >>> scf = covmats.SparseCholeskyFactor( ... sp.sparse.csc_array(L), sp.sparse.csc_array(D), P ... ) >>> cov = covmats.CovViaSparsePrecisionCholesky(scf) >>> x = np.random.default_rng(0).random(Q.shape[0]) >>> np.allclose(cov.solve(cov @ x), x) True
- __init__(scf: SparseCholeskyFactor, sparse_precision: sparray | None = None) None[source]#
Initialize the instance.
- Parameters:
scf (SparseCholeskyFactor) – Lower triangle of the sparse precision matrix Cholesky factorization.
sparse_precision (Optional[sp.sparse.sparray], optional) – Sparse precision matrix (inverse of the covariance matrix), by default None
Properties
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 with shape (n, n).
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.
Perform the adjoint (transpose) of the colorizing transformation.
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).
Return x = A^{-1} b.
Explicit dense representation of the covariance matrix with shape (n, n).
Transpose this linear operator.
Perform a whitening transformation on data.