Tue 20 Jun 2017 04:49:44 PM UTC, comment #3:
Marco is correct. A zero matrix is positive semidefinite, so
should return 0 for any integer n. My patch fixes this.
Marco is also correct that
is positive semidefinite, and so perhaps it would be desirable for
to return 0.
The way the code works is by attempting a series of Cholesky decompositions (https://en.wikipedia.org/wiki/Cholesky_decomposition). Note that theoretically, a Cholesky decomposition exists for any positive semidefinite matrix, but it is only unique for strictly positive definite matrices. In practice however,
calculates the Cholesky decomposition successfully only if A is strictly positive definite. If this returns a nonzero p, this indicates that the decomposition was unsuccessful and so A is not strictly positive definite.
We want the code to tell us whether a matrix A is
- strictly positive definite
- positive semidefinite
- neither
What it actually checks for is this:
- Are all of the eigenvalues of A at least tol bigger than 0? If so then tell the user that A is strictly positive definite.
- If not, then are all of the eigenvalues of A + tol bigger than 0? If so then tell the user that the A is positive semidefinite.
- If not, then tell the user that A is neither strictly positive definite nor positive semidefinite.
The problem comes from specifying a tolerance of 0. Regarding
the eigenvalues are not at least tol bigger than 0, so the code does not return strictly positive definite. Also, the eigenvalues + tol are not bigger than zero, so the code does not return positive semidefinite. So the code returns the third option: neither.
Calling the function with a tolerance of 0 is probably bad practice in general, so I'm not sure you want to account for that use case. Clarifying the documentation or throwing a warning if the user tries to use a tolerance of 0 might be a good idea.
|