# near_psd¶

copulae.core.linalg.near_psd(cov, method='clipped', threshold=1e-15, n_fact=100)[source]

Finds the nearest covariance matrix that is positive (semi-) definite

This converts the covariance matrix to a correlation matrix. Then, finds the nearest correlation matrix that is positive semi-definite and converts it back to a covariance matrix using the initial standard deviation.

The smallest eigenvalue of the intermediate correlation matrix is approximately equal to the threshold. If the threshold=0, then the smallest eigenvalue of the correlation matrix might be negative, but zero within a numerical error, for example in the range of -1e-16.

Input covariance matrix must be symmetric.

Parameters
• cov ((N, N) array like) – Initial covariance matrix

• method ({ 'clipped', 'nearest' }, optional) –

If “clipped”, this function clips the eigenvalues, replacing eigenvalues smaller than the threshold by the threshold. The new matrix is normalized, so that the diagonal elements are one. Compared to “nearest”, the distance between the original correlation matrix and the positive definite correlation matrix is larger. However, it is much faster since it only computes eigenvalues once.

If “nearest”, then the function iteratively adjust the correlation matrix by clipping the eigenvalues of a difference matrix. The diagonal elements are set to one.

• threshold (float) – Clipping threshold for smallest eigenvalue

• n_fact (int) – Factor to determine the maximum number of iterations if method is set to “nearest”

Returns

positive semi-definite matrix

Return type

ndarray