-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
ENH: sparse.linalg: Add the feature of spectral norm of sparse matrices #14855
Conversation
Use "np.integer" in "issubdtype" Use LOBPCG directly instead of "scipy.sparse.linalg.svds" Find the "lobpcg" module
This can be more easily done just by calling |
Dear Andrew @lobpcg A = [[-4, -3, -2],
[-1, 0, 1],
[2, 3, 4]]; the error between the smallest singular value solved by |
The case you provide above is for the smallest singular value, so I am also unsure how it relates to the spectral norm. |
@lobpcg In addition to the above reasons, there is another reason. For |
Dear Andrew, |
Why the smallest is needed for the norm? |
@lobpcg The largest sing. value is no problem on any platform, but the smallest sing. val will have problems on some specific platforms. |
This is because NumPy defines a - 2 norm, SciPy need to be aligned with NumPy on some operations. But from computational mathematics textbook, -2 norm is not defined. |
I recollect that svds does something special and strange with the smallest singular values, so I believe that there may be a difference that may justify a separate code for -2, indeed. |
Dear Andrew @lobpcg |
Possible, look at the end of svds code. |
@lobpcg I modified the file |
…in 2/-2 norm of sparse matrices
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.
You need to make sure that everything works in single precision as well. So you cannot use fixed constants like 1e-14
You also need unit tests in both precisions.
Okay, I try it. |
… for matrices with different accuracy
For your absolute constant use a power of np.finfo(dtype).eps with dtype=np.float64 or np.float32 depending on the case |
I resubmitted the PR, used 50 * np.finfo(...).eps in the codes (7d792a7), Could I do it this way? |
The expression of the threshold should also depend on the shape and probably some norm of the input, like in the original code. |
Yes, the threshold 50 in the code also indeed depend on float32 or float64. For float64, the threshold is ~20 (there are some small fluctuations), whereas for float32, the threshold is probably 30-50 (affected by different platforms) |
Not good, the expression should be the same for different dtypes. Try using a fixed power or log of eps instead of multiplying eps by different constants. |
Dear Andrew, setting it to 50 is only to cut it off within the fluctuation range of machine accuracy,but the fluctuation seems doesn't have much regularity and there is no formula guide to rely on. |
I don't have much experience in error fluctuation caused by different platforms and different accuracy (float32 & float64). For the fixed power or log of eps, I have no idea yet currently. What value do you think is more reasonable?Thanks. |
My suggestion is to try obtaining both values ~ |
Okay, I'll try to find it, thanks. |
Because I can't reproduce this problem on my laptop [macOS Big Sur-64bit] and server [Ubuntu-20.04-64bit] (the problem only occurs in Win32 environment in Azure Pipelined of SciPy CI/CR), I've turn it into a draft and continue to test it by submitting the draft. If there are any email reminders/bother, please ignore them until I'm ready to please you review again. Thanks. |
Dear Andrew @lobpcg I make some tests varous platform in Docker, there is no rule for the fluctuation range of the result. However, I find a bug from NumPy when I check the call process in NumPy and SciPy (Notice: the For a |
Please submit a bug report and the fix, since you have already found it! |
Okay, I'll submit the bug report and fix it later. Thanks. |
For the smallest SVD, have a look at #11829 |
Reference issue
What does this implement/fix?
In this PR, the spectral norm (2-norm and -2-norm) of the matrices are added, the singular values are computed by efficient LOBPCG indirectly.
Additional information