-
-
Notifications
You must be signed in to change notification settings - Fork 518
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
is_positive_definite returns wrong results #33100
Comments
comment:1
This also fails for larger matrices, such as these linear combinations of positive definite matrices (for many seeds):
|
comment:2
My first thought was that we should be able to delete First, the generic Second, the subclass implementation of
while
or
We'd have to either tweak the default tolerance there, or again maybe just delete the subclass method. The "naive" algorithm now defers to a superclass implementation where the default tolerance works. |
Dependencies: #33107 |
Commit: |
comment:3
Rather than remove the subclass New commits:
|
Author: Michael Orlitzky |
Branch: u/mjo/ticket/33100 |
comment:4
I agree with using the "naive" algorithm here and do not see why it would be more naive/less appropriate than the "orthonormal" one. For the orthonormal algorithm, no tolerance would be large enough to work for all such matrices that are Hermitian in an exact sense, when considered entrywise. Scipy 1.8.0 will also have a function scipy.linalg.ishermitian which works like the naive algorithm, i.e. entrywise. Replying to @orlitzky:
I am a bit hesitant to replace a Scipy implementation by a pure Sage implementation. Upstream has confirmed here that This would make
|
comment:5
Replying to @mwageringel:
Yeah, the subclass should be doing that anyway, since the superclass does it. (Users shouldn't see different qualitative behaviors from a method when you change the underlying representation of the matrix's entries.) I haven't checked but scipy is almost certainly faster even though I did my best to make it fast in sage. On the other hand, it's nice not to have copy & pasted the entire method's documentation.
The superclass |
comment:6
Replying to @orlitzky:
Unless you strongly prefer otherwise, I tend towards staying with using Scipy for the Cholesky decomposition.
Ok, dropping |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:8
I left |
Reviewer: Markus Wageringel |
comment:9
Ok, this looks good to me then. Thank you for implementing this. |
This comment has been minimized.
This comment has been minimized.
comment:11
Merge failure on top of: 429528ecd0 Trac #20343: Adding sage/plot/tikzpicture.py d3f74f63be Trac #33085: adjust dochtml label so doctests pass when html doc is not built/installed d70747d13f Trac #33094: update URLs in SPKG.rst for ECL 03f57e6ad1 Trac #32922: Change parameter name 1057236215 Trac #30999: expose method hyperbolicity in graphs 9b4a9198e2 Trac #33035: random doctest failure in src/sage/tests/book_stein_ent.py fee8e65057 Trac #32264: Convenience syntax for quaternion ideals c2bcc90ea8 Trac #31005: Add traceback information to exceptions during docbuild 3f697607e8 Trac #33159: wrong result solving equation system with symbolic matrix bf9673f1a5 Trac #33158: kRegularSequence: minimization wrong 01ff471e9f Trac #33157: Issue with SR → [RC]BF conversion 379c88d769 Trac #33154: random doctest failure in sage.plot.matrix_plot 9fa34b02a7 Trac #33151: sage-conf_pypi does not build wheelhouse ffe0b98c81 Trac #33148: fix doctest in quantum_group_gap 0bf6a86003 Trac #33107: Generic cholesky() fails on the trivial matrix 3b02b82340 Trac #33103: gitpod integration using Docker images from portability testing workflow af5c4c48ad Trac #33098: Add more void packages to distros/void.txt 9b61187847 Trac #33096: src/tox.ini (relint): Exclude editor temp files etc. 217156c781 Trac #33064: sage_docbuild: fails when cache cannot be saved c2097f4654 Trac #33039: Random doctest failure in continued_fraction_gosper 53781ca1e5 Trac #33015: Random failure in number_field_element.pyx 0ecfd27027 Trac #33005: Add feature for pdftocairo 961f91527a Trac #32970: fix parent of 0th Bernoulli polynomial 527fbc473d Trac #32877: Remove superfluous set_random_seed() calls d3aec55fe5 Trac #32873: sage.features, sage_setup: Replace use of distutils.errors by setuptools 3154d1d97d Trac #32856: Get rid of "# optional - build" d87eeb3e7f Trac #30362: Add symplectic structures 030af8db7e Trac #29865: Modularization of sagelib: Break out separate packages sagemath-objects, sagemath-categories 1fed3d635c Trac #33189: Make tests pass with arb 2.22 1ea6801ffb Trac #33131: Installation manual: Add decision tree, remove mention of Sage-mirror-hosted binary distributions 209b71330d Trac #33101: lrslib: fix doctest in game_theory/parser.py 73aa4f3e4d Trac #33077: pari-jupyter: Reinstate 180b9ee2fb Trac #30933: GH Actions: Repair upload of docker images to docker.pkg.github.com e67e1ee810 Trac #8450: intermediate complex expression in real functions make many plot functions fail d03870b5f2 Trac #33206: PDF documentation links in Documentation from Jupyter notebook are broken 8ea92d5 Updated SageMath version to 9.5.rc3 merge was not clean: conflicts in src/sage/matrix/matrix_double_dense.pyx |
comment:12
(brought to you by sagemath/git-trac-command#57) |
comment:13
For some reason, I did not receive an email notification for comment 11. Also, this does not seem so useful without knowing which of the three dozen tickets causes a merge conflict, so I have to wait for the new beta anyway. It would be more helpful if the CI identifies merge conflicts between positively reviewed tickets, so that one can resolve conflicts before it even gets any attention by the release manager. |
comment:14
Thanks for the input! Yes, this can certainly be refined. |
comment:15
Set milestone to sage-9.6 after Sage 9.5 release. |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:17
- # avoid abs() which is missing for finite fields.
- if d > tolerance or -d > tolerance:
+ # abs() support is spotty
+ if (d*d.conjugate()).sqrt() > tolerance: I am not completely sure about theses changes. Square roots do not always exist in the same field, such as cyclotomic fields for which For finite fields, the documentation advises against relying on comparisons as well. Though, technically they should work in our case, i.e. if the integer representation of a finite field element is compared to a tolerance of 0. It might be better to explicitly check whether |
comment:18
Replying to @mwageringel:
This lurking doubt is what kept me from setting it back to needs_review right away. A priori we could square both sides to avoid roots, but I still have some questions. For the moment, a lot of this stuff is broken in corner cases anyway, so I don't feel too bad about making incremental but imperfect improvements so long as they don't hurt any existing use cases. But for finite fields I think you're right, and I vaguely remember coming to the same conclusion. If the fields are exact, the tolerance should be zero unless you override it, and it's only by accident that the comparison works but it does work. If a tolerance is given, though, I'm not even sure what the user could expect to happen. |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:20
Let's see what patchbot says about this one... |
comment:21
There is a merge failure, but otherwise this looks good to me, as long as the tests pass. |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:23
It rebased cleanly, I think I maybe it wanted me to drop the commits from #33107. |
comment:24
Thanks. |
Changed branch from u/mjo/ticket/33100 to |
For some double dense matrices that are not positive definite, Sage incorrectly claims that they are:
Clearly,
A
is not even Hermitian. The implementation relies on testing whether a Cholesky decomposition exists or not, but.cholesky()
gives an incorrect result for this matrixwhile for most other matrices this would raise an error.
The SciPy documentation is not entirely clear about this, but it seems that SciPy assumes that the matrix is already Hermitian positive-definite and thus only considers half the matrix (see SciPy issues 2116 and 15012).
This ticket adds a check whether the matrix is Hermitian before computing the Cholesky decomposition, which resolves the problem. The default algorithm for
is_hermitian
is changed from "orthonormal" to "naive".Depends on #33107
CC: @orlitzky
Component: linear algebra
Author: Michael Orlitzky
Branch/Commit:
1d6bae6
Reviewer: Markus Wageringel
Issue created by migration from https://trac.sagemath.org/ticket/33100
The text was updated successfully, but these errors were encountered: