[Math] Fast way of checking whether a matrix is positive definite without Cholesky decomposition

matricespositive definite

I would like to check whether a matrix $A$ is positive definite. Previous answers to this question have pointed to the Cholesky decomposition. However, since my framework of choice is Tensorflow, I cannot catch and handle the exception thrown when the decomposition discovers that the matrix is not positive definite, so I need another way.

Another approach I have seen is to compute the eigenvalues, and check whether any of them are negative. This works, but it is slow. I have also heard the suggestion to compute the smallest eigenvalue. This makes sense to me — if it is negative, we know the matrix is not positive definite — but I am unsure how to do this efficiently. I would be grateful for some pointers!

Best Answer

Use the Cholesky Decomp, I don't understand why you can't handle an exception. This is from StackOverflow.

import numpy as np

    def is_pd(K):
        try:
            np.linalg.cholesky(K)
            return 1 
        except np.linalg.linalg.LinAlgError as err:
            if 'Matrix is not positive definite' in err.message:
                return 0
            else:
                raise