Check if the matrix is ​​SPD

What will be the fastest (runtime) to check if the matrix is ​​symmetrically positively defined in Matlab? I checked this test for a large number of sparse matrices, the size (size of which) varies from 10,000 to 100,000?

Edit:

Cholesky is overly expensive for my purpose. First I need a dirty check, if it gives an indication that the matrix can be spd, then I can more reliably check only this matrix with CHOL

+4
source share
3 answers

As indicated here , you can use the chol function to check if the matrix is ​​PD.

The CHOL function provides an optional second output argument "p" which is zero if the matrix is ​​positive definite. The CHOL function will return an error if it is provided with only one output argument, and also a matrix is ​​specified that is not positive definite. NOTE. CHOL expects its input matrix to be symmetric and only looks at the upper triangular part of the matrix.

As for symmetry, you can use the following function:

 issym = @(m) isequal(tril(x), triu(x)'); 
+3
source

I think this is a non-trivial problem to do this effectively. The Cholesky algorithm will fail if the matrix is ​​not positive definite, so it’s best to realize yourself, which will also have the advantage of controlling what to do when the algorithms fail because the input is not positive definite. I use C # instead of Matlab for my mathematical programming, and my Cholesky implementation is just a few lines, so it is not complicated. If you use some other algorithm, then depending on how it is implemented, if you use an asymmetric matrix, you may get misleading results, because some implementations assume that the matrix is ​​symmetric. The only quick preliminary test I can think of is to check the matrix trace , which will be positive if the matrix is ​​SPD.

+2
source

I think you can take a look at the eigenvalues ​​of your matrix and see if they are all different and really appreciated.

Therefore, you can call the eig function as follows:

 [V,D] = eig(A) 

I hope this helps

+1
source

Source: https://habr.com/ru/post/1482095/


All Articles