Repository navigation
fix(rotator): make MatrixRotator Haar distributed - #258
Merged
Merged
Conversation
The Householder Q factor that MatrixRotator stored has a fixed determinant and a negative first entry, so it is not Haar distributed. Give column i of Q the sign of R(i, i) (Mezzadri 2007, Section 5). A given seed now yields a different matrix; saved rotators and indexes are unaffected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MatrixRotatorused the Q factor ofEigen::HouseholderQRon a Gaussian matrix as returned. Eigen, like LAPACK, setsR(k, k) = -sign(pivot) * normfork < nand makes the last reflector the identity, soQ = H_1 ... H_{n-1}:det Q = (-1)^(n-1)and, for dimension 2 and up,Q(0, 0) < 0for every seed. Such a Q is not Haar distributed, neither on O(n) nor on its coset.This PR gives column
iof Q the sign ofR(i, i)(Mezzadri, Notices of the AMS 54 (2007), Section 5), which makes Q Haar distributed. Only the firstdimrows ofQ^Tare stored, so only those rows are flipped.Effect
MatrixRotator(RotatorType::MatrixRotator, also whenIVForQuantizedGraphuse it) and Pythonquant.Rotator(method="matrix"). Saved rotators and indexes store their matrix and load unchanged; the persistence fixtures pass unchanged.dim * padded_dimentries after the QR factorization.Tests
MatrixRotatorFactoryTest.SeededMatricesTakeBothSignsAsHaarRequires: over 64 seeds at dimension 3, both signs ofQ(0, 0)and ofdet Qmust occur. The old code fails it (64/64 negative entries, 0/64 negative determinants); a Haar-distributed rotator fails it with probability about 2^-62.test_matrix_rotation_takes_both_signs: the same check throughquant.Rotatorat dimension 32.ctest: 615 tests, 1 skipped (ThreadCount.BoundParallelForUsesRuntimePlacementAndPropagatesErrors, as before). Python: 1208 passed, 2 skipped, with the package rebuilt (native optimization off).check-format.sh,check-python.sh, fullcheck-tidy.shandmkdocs build --strictpass.