# random_sparse_spd_matrix¶

probnum.problems.zoo.linalg.random_sparse_spd_matrix(rng, dim, density, chol_entry_min=0.1, chol_entry_max=1.0, format='csr')[source]

Random sparse symmetric positive definite matrix.

Constructs a random sparse symmetric positive definite matrix for a given degree of sparsity. The matrix is constructed from its Cholesky factor $$L$$. Its diagonal is set to one and all other nonzero entries of the lower triangle are sampled from a uniform distribution with bounds [chol_entry_min, chol_entry_max]. The resulting sparse matrix is then given by $$A=LL^\top$$.

Parameters

random_spd_matrix

Generate a random symmetric positive definite matrix.

Examples

>>> import numpy as np
>>> from probnum.problems.zoo.linalg import random_sparse_spd_matrix
>>> rng = np.random.default_rng(42)
>>> sparsemat = random_sparse_spd_matrix(rng, dim=5, density=0.1)
>>> sparsemat
<5x5 sparse matrix of type '<class 'numpy.float64'>'
with 9 stored elements in Compressed Sparse Row format>
>>> sparsemat.todense()
matrix([[1.        , 0.        , 0.87273813, 0.        , 0.        ],
[0.        , 1.        , 0.        , 0.        , 0.        ],
[0.87273813, 0.        , 1.76167184, 0.        , 0.        ],
[0.        , 0.        , 0.        , 1.        , 0.72763123],
[0.        , 0.        , 0.        , 0.72763123, 1.5294472 ]])

Return type

spmatrix