-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Use gaussian elimination for positive-definite check #19205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use gaussian elimination for positive-definite check #19205
Conversation
|
✅ Hi, I am the SymPy bot (v158). I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like:
This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.6. Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
Codecov Report
@@ Coverage Diff @@
## master #19205 +/- ##
=============================================
- Coverage 75.666% 75.651% -0.016%
=============================================
Files 651 651
Lines 169336 169383 +47
Branches 39970 39981 +11
=============================================
+ Hits 128131 128140 +9
- Misses 35605 35637 +32
- Partials 5600 5606 +6 |
| m = Matrix([[2, -1, 0], [-1, 2, -1], [0, -1, 2]]) | ||
| assert m._eval_is_positive_definite(method='eigen') == True | ||
| assert m._eval_is_positive_definite(method='LDL') == True | ||
| assert m._eval_is_positive_definite(method='CH') == True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these tests not needed any more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed those methods so they cannot be tested
|
If the matrix is not square should we say that |
|
I have left them undefined because I found nobody had asserted that any nonsquare or nonhermitian matrix is not positive definite. But I have found a generalization that can be extended for nonhermitian matrices in https://www.jstor.org/stable/2317709, which also notes about some properties like the existance of the LR factorization or the positive eigenvalues. Though |
|
That paper has other useful properties for example that if a matrix positive definite then the diagonal entries are positive (not sure if this only applies for real matrices). The contrapositive leads to a much cheaper check of positive definiteness: if any diagonal entry is not positive then the matrix is not positive definite. |
|
It's probably worth having a shortcut for the case where the answer is probably unknowable. The original issue here came from a symmetric matrix where every entry was a symbol with no assumptions. I think that if we literally don't know whether any element on the diagonal is positive or not then it's very unlikely that we will be able to get determine if the matrix as a whole is positive definite e.g.: Can you think of any examples where we don't know if any of the diagonals is positive or not but we do know that the matrix is or is not positive definite? |
|
Actually I guess this would be an example: In [9]: x = Symbol('x', real=True)
In [10]: M = Matrix([[sin(x), 2], [2, sin(x)]])
In [11]: M
Out[11]:
⎡sin(x) 2 ⎤
⎢ ⎥
⎣ 2 sin(x)⎦And in this example we don't know whether anything is positive or negative but we know at least one eigenvalue is negative either way: In [21]: M = Matrix([[sin(x), 2*sin(x)], [2*sin(x), sin(x)]])
In [22]: M
Out[22]:
⎡ sin(x) 2⋅sin(x)⎤
⎢ ⎥
⎣2⋅sin(x) sin(x) ⎦
In [23]: M.eigenvals()
Out[23]: {-sin(x): 1, 3⋅sin(x): 1} |
|
Looks good. Merging |
|
What exactly is the relationship between row and column diagonal dominance? Are they equivalent? |
|
They are trivially equivalent for symmetric or hermitian matrices which is sufficient for this test. For other cases I'm not familiar enough to assert. |
References to other Issues or PRs
Fixes #18955
Brief description of what is fixed or changed
I have changed positive definite check to use division free gaussian elimination, which hopefully gives less bloated expressions, and used berkowitz determinant check for positive semidefinite check which can suffer less from zero testing.
Other comments
Release Notes
is_strongly_diagonally_dominantandis_weakly_diagonally_dominantproperties forMatrix.