How to find the nearest positive definite matix

40 views (last 30 days)
Hi, I have a quesiton, I want to use the chol function in matlab but the function requires a strict positive definite matrix as input. How can I find the nearest positive definite matrix?
Thanks

Answers (2)

Bruno Luong
Bruno Luong on 10 Jul 2019
Edited: Bruno Luong on 28 Jul 2020
First step of preparation is to "symmetrize" the matrix
A = 0.5*(A + A')
Why? Because MATLAB engine selects the algorithm depending on the matrix form, it can fail to detect the matrix is hermitian (symmetric) if there is numerical error and isequal(A, A') returns FALSE, even if A is very close to A'.
Next, if it's not enough find the smallest eigen value lbdmin of A (use for example EIGS function), then change A by adding
A + max(-lbdmin,0)*speye(size(A)) % for sparse matrix, to keep it sparse
for dense matrix you might prefer not bother of speye.
A + max(-lbdmin,0)*eye(size(A))
This is the theory, in practice you might add some margin to overcome floating point truncation by boosting with some factor.
boost = 2; % close to 1 is better
A + boost*max(-lbdmin,0)*speye(size(A));
NOTE: This is not the nearest matrix (the nearest is to project negative eigen space to 0 and untouch the positive one, see John's answer), but convenient to get SDP matrix. Nearest SPD of sparse matrix is likely a dense matrix, which might not be desirable for large-side sparse matrix.
  1 Comment
Ron van de Sand
Ron van de Sand on 6 May 2020
Edited: Ron van de Sand on 6 May 2020
Hello,
I ran in into a similar problem. Can you suggest any referene (Paper, Book etc.) regarding this topic?

Sign in to comment.


John D'Errico
John D'Errico on 6 May 2020
Edited: John D'Errico on 6 May 2020
You can always just download my nearestSPD function from the file exchange. (Note that it does come with a reference to how it works.)
From some work by N. Higham: "The nearest symmetric positive semidefinite matrix in the Frobenius norm to an arbitrary real matrix A is shown to be (B + H)/2, where H is the symmetric polar factor of B=(A + A')/2."
nearestSPD uses the above idea, then verifies the result is indeed SPD using chol to verify it has suceeded. If there is still an issue, it applies a further tweak as needed.
  2 Comments
Ron van de Sand
Ron van de Sand on 6 May 2020
Thnak you for your quick response! I just needed some more information about the topic as I'm starting to dive into the topic. Thank you.

Sign in to comment.

Categories

Find more on Arithmetic Operations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!