0
$\begingroup$

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!

$\endgroup$
0
$\begingroup$

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 
$\endgroup$
  • $\begingroup$ I am afraid I am using tensorflow, not numpy. Tensorflow's graph-based execution means errors cannot be handled dynamically. See: github.com/GPflow/GPflow/issues/553 . Also: github.com/tensorflow/tensorflow/issues/10332 $\endgroup$ – noctilux Oct 17 '18 at 3:42
  • $\begingroup$ this is clearly an issue for stack overflow. the best choice is still cholesky because it is more computationally expensive to compute eigenvalues. $\endgroup$ – Shogun Oct 17 '18 at 3:44
  • $\begingroup$ I don't know much of anything about tensorflow and why it can't handle simple errors.. $\endgroup$ – Shogun Oct 17 '18 at 3:46
  • $\begingroup$ or at best code review, not mathstack it isn't a question about math. $\endgroup$ – Shogun Oct 17 '18 at 3:53
  • $\begingroup$ Thank you for your comment, but I do think it is a math question. If there is no fast / convenient alternative to check positive definiteness, that's fine, but I would like to know if there is, hence this question. $\endgroup$ – noctilux Oct 17 '18 at 4:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.