comet_maths.linear_algebra.matrix_calculation.nearestPD_cholesky

comet_maths.linear_algebra.matrix_calculation.nearestPD_cholesky#

comet_maths.linear_algebra.matrix_calculation.nearestPD_cholesky(A: ndarray, diff: float | None = 0.05, corr: bool | None = False, return_cholesky: bool | None = True) ndarray[source]#

Find the nearest positive-definite matrix

Parameters:
  • A – correlation matrix or covariance matrix

  • diff – maximum difference that the error correlation matrix is allowed to be changed by to make it positive definite. Defaults to 0.001

  • corr – boolean to indicate whether error correlation matrix is used (True) or error covariance matrix is used (False). Defaults to False

  • return_cholesky – boolean to indicate whether the cholesky decomposition should be returned (True) or just the nearest positive definitive error correlation/covariance matrix (False). Defaults to True.

Returns:

nearest positive-definite matrix

Copied and adapted from [1] under BSD license. A Python/Numpy port of John D’Errico’s nearestSPD MATLAB code [2], which credits [3]. [1] https://gist.github.com/fasiha/fdb5cec2054e6f1c6ae35476045a0bbd [2] https://www.mathworks.com/matlabcentral/fileexchange/42885-nearestspd [3] N.J. Higham, “Computing a nearest symmetric positive semidefinite matrix” (1988): https://doi.org/10.1016/0024-3795(88)90223-6