This function transforms a symmetric matrix into a positive definite matrix by replacing any negative or excessively small eigenvalues with a specified small positive value (epsilon).

make_positive_definite(M, epsilon = 1e-06)

Arguments

M

a square, symmetric numeric matrix.

epsilon

a small positive numeric threshold below which eigenvalues are replaced(default 1e-6).

Value

a symmetric positive definite corrected matrix of the same dimensions as the original

Details

The correction relies on the eigendecomposition M = V . D . V', where V is the matrix of eigenvectors and D the diagonal matrix of eigenvalues. Negative or near-zero eigenvalues in D are moved to epsilon before reconstructing the matrix. The result is numerically close to the original matrix M when the original matrix is already near positive definite.