# random_spd_matrix¶

probnum.problems.zoo.linalg.random_spd_matrix(dim, spectrum=None, random_state=None)[source]

Random symmetric positive definite matrix.

Constructs a random symmetric positive definite matrix from a given spectrum. An orthogonal matrix $$Q$$ with $$\operatorname{det}(Q)$$ (a rotation) is sampled with respect to the Haar measure and the diagonal matrix containing the eigenvalues is rotated accordingly resulting in $$A=Q \operatorname{diag}(\lambda_1, \dots, \lambda_n)Q^\top$$. If no spectrum is provided, one is randomly drawn from a Gamma distribution.

Parameters

random_sparse_spd_matrix

Generate a random sparse symmetric positive definite matrix.

Examples

>>> from probnum.problems.zoo.linalg import random_spd_matrix
>>> mat = random_spd_matrix(dim=5, random_state=0)
>>> mat
array([[10.49868572, -0.80840778,  0.79781892,  1.9229059 ,  0.73413367],
[-0.80840778, 15.79117417,  0.52641887, -1.8727916 , -0.9309482 ],
[ 0.79781892,  0.52641887, 15.56457452,  1.26004438, -1.44969733],
[ 1.9229059 , -1.8727916 ,  1.26004438,  8.59057287, -0.44955394],
[ 0.73413367, -0.9309482 , -1.44969733, -0.44955394,  9.77198568]])


Check for symmetry and positive definiteness.

>>> np.all(mat == mat.T)
True
>>> np.linalg.eigvals(mat)
array([ 6.93542496, 10.96494454,  9.34928449, 16.25401501, 16.71332395])

Return type

ndarray