-
Notifications
You must be signed in to change notification settings - Fork 54
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
Add hermitian()
to matrix gallery
#1199
Conversation
* hermitian: add function definition * implement hermitian * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Set default dtype to complex * Edit docs * Apply suggestions from code review * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix reference to types --------- Co-authored-by: Claudia Comito <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
hermitian()
to matrix gallery
Thank you for the PR! |
Thank you for the PR! |
Thank you for the PR! |
Codecov Report
@@ Coverage Diff @@
## main #1199 +/- ##
==========================================
- Coverage 92.19% 92.16% -0.03%
==========================================
Files 75 75
Lines 10699 10713 +14
==========================================
+ Hits 9864 9874 +10
- Misses 835 839 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 3 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
heat/utils/data/matrixgallery.py
Outdated
dtype: Type[datatype] = core.complex64, | ||
) -> DNDarray: | ||
""" | ||
Generates a Hermitian matrix of size `(n,n)`. A Hermitian matrix is a complex square matrix that is equal to its conjugate transpose. |
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.
In essence, the matrices constructed below are distributed according to "Whishart distribution" (https://en.wikipedia.org/wiki/Wishart_distribution). We could add a reference to "Marchenko-Pastur distribution" for their singular values (https://en.wikipedia.org/wiki/Marchenko%E2%80%93Pastur_distribution) if we scale appropriately.
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.
@mrfh92 would you update the docs? Thanks a lot!
heat/utils/data/matrixgallery.py
Outdated
real_dtype = core.float32 if dtype is core.complex64 else core.float64 | ||
matrix = randn(n, n, dtype=real_dtype, split=split, device=device) | ||
matrix += 1j * randn(n, n, dtype=real_dtype, split=split, device=device) | ||
return matrix @ core.conj(matrix).T |
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.
Two comments:
- if we scale by 1/matrix.shape[0] the singular values are distributed according to Marchenko Pastur distribution (see above)... also this scaling might remove unwanted effects when choosing larger and larger matrices
- The formula yields, of course, and they are even positive definite (with probability 1? - Im not an expert in this stuff...). However, doing the matrix-multiplication is quite expensive ... can we add something like an option "positive_definite" that triggers the formula used so far and use
return matrix + core.conj(matrix).T.resplit(matrix.split)
instead for the remaining cases?
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.
Thanks, done
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.
only small comments on docs and formula used for generation of the random matrices.
But in prinicple, this PR is ready for merging even without these changes.
Thanks for the work 👍
Updated docs for `hermitian` Added scaling factor for the positive definite matrices Added distinction of real and complex data types
for more information, see https://pre-commit.ci
extended tests: * added tests for the positive definite case and real data-types
for more information, see https://pre-commit.ci
…ine with latex formulas...
Thank you for the PR! |
Thank you for the PR! |
@ClaudiaComito since I have done some changes here last week after my review it might be more useful if now you review again |
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.
Looks fine to me, but since the last changes have been done by me, maybe somebody else should review too.
Due Diligence
main
for new features, latest release branch (e.g.release/1.3.x
) for bug fixesDescription
Creating a new PR to add tests for the Hermitian test matrix implemented in #1086.
Workflow:
hermitian()
to matrix gallery #1086 into this PR ✅Issue/s resolved: #1073
Changes proposed:
Type of change
Memory requirements
Performance
Does this change modify the behaviour of other functions? If so, which?
no