Skip to content
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

Merged
merged 14 commits into from
Sep 4, 2023

Conversation

ClaudiaComito
Copy link
Contributor

@ClaudiaComito ClaudiaComito commented Aug 19, 2023

Due Diligence

  • General:
    • base branch must be main for new features, latest release branch (e.g. release/1.3.x) for bug fixes
    • title of the PR is suitable to appear in the Release Notes
  • Implementation:
    • unit tests: all split configurations tested
    • unit tests: multiple dtypes tested
    • documentation updated where needed

Description

Creating a new PR to add tests for the Hermitian test matrix implemented in #1086.

Workflow:

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

@ghost
Copy link

ghost commented Aug 19, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

* 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>
@ClaudiaComito ClaudiaComito changed the title Add Hermitian test matrix Add hermitian() to matrix gallery Aug 19, 2023
@github-actions
Copy link
Contributor

Thank you for the PR!

@github-actions
Copy link
Contributor

Thank you for the PR!

@github-actions
Copy link
Contributor

Thank you for the PR!

@codecov
Copy link

codecov bot commented Aug 19, 2023

Codecov Report

Merging #1199 (833522d) into main (089ab2f) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

❗ Current head 833522d differs from pull request most recent head 08d3dca. Consider uploading reports for the commit 08d3dca to get more accurate results

@@            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     
Flag Coverage Δ
unit 92.16% <100.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
heat/utils/data/matrixgallery.py 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

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.
Copy link
Collaborator

@mrfh92 mrfh92 Aug 21, 2023

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.

Copy link
Contributor Author

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!

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
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done

Copy link
Collaborator

@mrfh92 mrfh92 left a 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 👍

mrfh92 and others added 8 commits August 25, 2023 09:37
Updated docs for `hermitian`
Added scaling factor for the positive definite matrices 
Added distinction of real and complex data types
extended tests: 
* added tests for the positive definite case and real data-types
@github-actions
Copy link
Contributor

Thank you for the PR!

@github-actions
Copy link
Contributor

Thank you for the PR!

@mrfh92
Copy link
Collaborator

mrfh92 commented Aug 31, 2023

@ClaudiaComito since I have done some changes here last week after my review it might be more useful if now you review again
(sry I just see that I cant assign you to be reviewer for your own PR)

@mrfh92 mrfh92 requested review from mrfh92 and mtar and removed request for mrfh92 August 31, 2023 14:10
Copy link
Collaborator

@mrfh92 mrfh92 left a 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.

@ClaudiaComito ClaudiaComito merged commit 425eba6 into main Sep 4, 2023
41 checks passed
@mtar mtar removed the PR talk label Sep 11, 2023
@mtar mtar deleted the 1073-Add_Hermitian_to_matrix_gallery branch February 28, 2024 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Hermitian to matrix gallery
4 participants