Skip to content

Definition of rtol in matrix_rank, lstsq and pinv #216

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

Closed
lezcano opened this issue Jul 1, 2021 · 0 comments · Fixed by #304
Closed

Definition of rtol in matrix_rank, lstsq and pinv #216

lezcano opened this issue Jul 1, 2021 · 0 comments · Fixed by #304
Labels
API change Changes to existing functions or objects in the API. topic: Linear Algebra Linear algebra.
Milestone

Comments

@lezcano
Copy link
Contributor

lezcano commented Jul 1, 2021

This can be seen as a follow-up of #211.

The current definition of rtol in these functions reads:

rtol: relative tolerance for small singular values. Singular values less than or equal to rtol * largest_singular_value are set to zero

This rules out the implementation of these functions via algorithms based on the QR decomposition, which goes against Design Principle 4: Implementation Agnosticism.

Note that in LAPACK, the meaning of rcond in SVD-based lstsq solvers and QR-solvers are somewhat equivalent. The one using a QR-decomposition defines RCOND for the decomposition

A * P = Q * [ R11 R12 ]
            [  0  R22 ]

as the smallest k for which \sigma_1(R11) / \sigma_{k+1}(R11) >= 1/RCOND, that is, the k for which RCOND\sigma_1(R11) >= \sigma_{k+1}(R11). In this case they assume R22 = 0. Note that this is an approximation of the definition for the SVD, for which if RCOND\sigma_1(A) >=\sigma_{k+1}(A) then \sigma_r(A) is considered zero for r = k+1,...,n.

For this reason, a solution to this problem might go through rewording the definition of rtol in this functions in terms of condition numbers, although it is not clear to me how to write this down in a simple way.

A simpler but less satisfactory way to address this would be to simply define rtol as

Singular values approximately less than or equal to rtol * largest_singular_value are set to zero.

I do not completely like this solution, because it sort of biases the definition to be based on SVD-like algorithms, and it takes a few seconds to realise that this is also what LAPACK's QR with pivoting is doing .

cc @rgommers @mruberry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API change Changes to existing functions or objects in the API. topic: Linear Algebra Linear algebra.
Projects
None yet
3 participants