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

rank(::QRPivoted) method? #1052

Closed
stevengj opened this issue Feb 6, 2024 · 4 comments · Fixed by JuliaLang/julia#54283
Closed

rank(::QRPivoted) method? #1052

stevengj opened this issue Feb 6, 2024 · 4 comments · Fixed by JuliaLang/julia#54283
Labels
good first issue Good for newcomers

Comments

@stevengj
Copy link
Member

stevengj commented Feb 6, 2024

Since pivoted QR is a rank-revealing calculation, it seems like we should have a LinearAlgebra.rank method that works directly on it. Something like:

function rank(F::QRPivoted; atol::Real=0, rtol::Real=min(size(F)...)*eps(real(float(one(eltype(F)))))*iszero(atol))
    m = min(size(F)...)
    m == 0 && return 0
    tol = max(atol, rtol*abs(F.R[1,1]))
    return something(findfirst(i -> abs(F.R[i,i]) <= tol, 1:m), m+1) - 1
end

should do it, no?

Of course, this won't necessarily return the same thing as the SVD-based rank (and is less reliable than SVD — it shouldn't be the default method for ::AbstractMatrix), but inconsistency is the fate of all numerical rank computations. In typical cases it should be close, one hopes, and if you have the QR you should be able to explicitly ask what numerical rank it reveals.

@oscardssmith oscardssmith added the good first issue Good for newcomers label Feb 6, 2024
@jefftrojan
Copy link

Hi, I am trying to make an attempt on this, I have a question tho... Could you explain the motivation behind introducing a rank calculation based on the pivoted QR decomposition?

@stevengj
Copy link
Member Author

stevengj commented Feb 14, 2024

It's way faster than the SVD (used by default for rank(A)), although it is somewhat less reliable. Moreover, if you already have the QR factorization, you might want to re-use it for the rank, and you should be allowed to query it for this information if you want.

See, for example, this discussion.

@aravindh-krishnamoorthy
Copy link
Contributor

aravindh-krishnamoorthy commented Feb 16, 2024

Hi, I am trying to make an attempt on this, I have a question tho... Could you explain the motivation behind introducing a rank calculation based on the pivoted QR decomposition?

This $2021$ blog post should also give you insight into the rank-revealing property of some matrix factorizations: What Is a Rank-Revealing Factorization?

@stevengj
Copy link
Member Author

stevengj commented Feb 23, 2024

Similarly, it might be nice to have a nullspace(::QRPivoted) method and a cond(::QRPivoted) method (via cond(R)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants