Hi all,

Is there a package in Julia which can be used to find a near positive definite matrix to a symmetric matrix?

In R there is a function nearPD that I can use or the function LaplacesDemon::as.positive.definite.

Thanks

Hi all,

Is there a package in Julia which can be used to find a near positive definite matrix to a symmetric matrix?

In R there is a function nearPD that I can use or the function LaplacesDemon::as.positive.definite.

Thanks

3 Likes

ProximalOperators exposes the `IndPSD`

type, whose proximal operator is the projection onto the positive semidefinite cone (with the Frobenius norm taken as distance).

More info here.

Is this what you’re looking for?

Edit: an example snippet

```
using ProximalOperators
# X is your symmetric matrix
P, _ = prox(IndPSD(), X)
```

8 Likes

@lostella This perfect! Exactly what I was looking for! This is awesome. Thank you very much!

I will need to incorporate that in a inplace function since I will use this in a MCMC loop.

Also, inv (inverse of a matrix) sometimes fails for a matrix borderline invertible. In R, there is a function as.inverse in the LaplacesDemon package which quickly replaces the smallest eigen values by an epsilon.

Are you aware of any function that can do that in Julia?

Thanks

You should be able to use the in-place version

```
prox!(P, IndPSD(), X)
```

which will write directly on a preallocated `P`

.

I don’t know of anything built-in that takes care of the singularity issue: you could either modify the code from ProximalOperators to account for that (instead of projecting eigenvalues to nonnegative values, you project them to a strictly positive region) or just add `epsilon*I`

to `P`

.

1 Like

Great! Indeed adding epsilon*I to P seems to do the trick. This works just perfect for me now!

I greatly appreciated your help.

Thank you!

1 Like

Feel free to mark my answer as a solution, so that other people can easily spot it. And of course if a better solution is given, feel free to mark that instead

indeed your answer works for me! How do I do mark your answer as the solution?

I am new to this.