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

Should \(SVD,...) truncate small singular values? #652

Open
andreasnoack opened this issue Aug 13, 2019 · 1 comment
Open

Should \(SVD,...) truncate small singular values? #652

andreasnoack opened this issue Aug 13, 2019 · 1 comment
Labels
breaking This change will break code needs decision A decision on this change is needed

Comments

@andreasnoack
Copy link
Member

andreasnoack commented Aug 13, 2019

This is a follow up on the discussion in JuliaLang/julia#32126. Currently, \ and inv truncate the smaller singular values, i.e. it actually computes a pseudo-inverse (or applies regularization if that is your preferred language). That is sometimes beneficial and the SVD is used for this purpose but I'm wondering if we should make the truncation/regularization explicit, i.e. let inv be the untruncated inverse and use pinv for the truncated version. Similarly, we could add a relative tolerance keyword argument to ldiv! which would default to zero, which would mean no truncation. The issue is \ which is an operator so we can't really control the behavior with an extra argument (when used as infix). Thoughts?

@andreasnoack andreasnoack added needs decision A decision on this change is needed breaking This change will break code labels Aug 13, 2019
@clason
Copy link

clason commented Aug 13, 2019

Nitpick: "regularization" is actually the correct language -- the truncation level corresponds to a regularization parameter. The pseudoinverse corresponds to inverting all non-zero singular values (and is therefore not numerically stable in the presence of very small singular values -- the only benefit of the pseudoinverse over the actual inverse is that it always exists even if the matrix is not invertible, in which case it corresponds to the least-squares solution of minimal norm).

As a mathematician, Matlab's silent use of (regularized) pseudoinverses when asked to solve a linear system has always bugged me to no end. My personal vote would therefore be to be fully explicit:

  • Make inv invert all singular values and either warn or error if zeros are encountered.
  • Make pinv invert all non-zero singular values (possibly warning if very small values are encountered).
  • Add a keyword to pinv (but not inv) that allows passing a truncation level (defaulting to zero).
  • Have \ behave as inv, but always error in the presence of zero values.
  • I have no strong opinion about ldiv! either way, but it might be useful to discuss what the tolerance keyword should control (and what "relative" is relative to -- does it involve the specific right-hand side?)

The error messages could (and should) then point towards the regularized version. This way users will know what they are doing and not rely on silent "do-what-I-mean" (where "I" is the software) behavior.

If you want to keep the default truncation (replacing "non-zero" above by "numerically non-zero"), I would advocate changing the default value to be absolute and related to the floating-point accuracy but not the dimension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This change will break code needs decision A decision on this change is needed
Projects
None yet
Development

No branches or pull requests

2 participants