Let's say I have an arbitrary diagonal matrix $A$. I want to convert this diagonal matrix to the closest matrix by some metric that is also PSD. Is there a standard way to do this?
This is for a program I'm writing. Currently, I have a small function to convert a diagonal to a PSD matrix but not to the closest PSD matrix.
def to_PSD(A_diag, eps=0.00001):
"""Convert an n-by-n diagonal matrix, represented as an n-vector, into a
positive semi-definite matrix.
"""
A_diag[A_diag < 0] = eps
A_diag[np.isclose(A_diag, 1)] = eps
return A_diag
Is there a better way to do this? (No code needed.)
You can define a distance between symmetric matrices $A$ and $B$ by using $d(A,B)=\sqrt{\mathrm{tr}(A-B)^T(A-B)}$, equivalently, by $d(A,B)=\sqrt{\sum_{i,j}(a_{ij}-b_{ij})^2}.$ For this metric, I think it's obvious that the closest psd matrix to diagonal matrix $A$ is obtained by replacing all negative entries on the diagonal of $A$ by zero. Also for the metric $\sqrt{\sum_{i\le j}(a_{ij}-b_{ij})^2}.$