-
Notifications
You must be signed in to change notification settings - Fork 26
svd stuck in infinite loop for certain matrices #81
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
Comments
Thanks for reporting this. I can reproduce the issue. I'll post an update once I've figured out what is going on. |
#82 seems to fix the issue for the reported matrices here. Please let me know if you see any convergence problems for other matrices once the patch is released. |
* Fix subproblem detection. Closes #81 * Some debug info * Fix computation of first Givens rotation in SVD when n1>1.
Thanks for the fix! However, even with the patch, here's a another matrix with problems: using GenericLinearAlgebra
m = [
0.3 0.0 0.0 0.0 0.0 0.2 0.3 0.0;
0.0 0.0 0.0 0.0 0.1 0.0 0.0 0.0;
0.0 -0.2 0.0 0.0 0.0 0.0 0.0 -0.2;
0.3 0.0 0.0 0.0 0.0 0.2 0.4 0.0;
0.0 0.4 -0.2 0.0 0.0 0.0 0.0 0.3;
0.2 0.0 0.0 0.0 0.0 0.0 0.2 0.0;
0.0 0.0 0.0 0.1 0.0 0.0 0.0 0.0;
0.0 0.3 -0.2 0.0 0.0 0.0 0.0 0.3]
svdvals!(copy(m), debug=true) #stuck in infinite loop Curiously, the convergence properties can be changed with a simple multiplication: svdvals!(10*copy(m), debug=true) #converges! |
This is indeed still an issue. I believe we need a dedicated solver for the 2x2 case. |
Just for your information, I've faced a similar problem when trying to decompose a (ill-conditioned) Hilbert matrix using using DoubleFloats
using GenericLinearAlgebra
# Hilbert matrix
# N <= 16 is OK
N = 17
A = zeros(Double64, N, N)
for j in 1:N, i in 1:N
A[i, j] = 1/Double64(i+j-1)
end
svd = GenericLinearAlgebra.svd(A) |
I ran into a similar issue to the one described here and I believe I've found the issue. It looks like there's a typo at GenericLinearAlgebra.jl/src/svd.jl Line 117 in f3e9d27
should be
This is what matches eq. 2.4 in http://www.netlib.org/lapack/lawnspdf/lawn03.pdf, and also the current version doesn't pass the check that scaling the matrix should scale μ by the same amount. If the bidiagonal matrix has small off-diagonal entries then μ can become very small (for the first matrix above matrix above I'm getting ~1e-41), which results in an impossible-to-meet stopping condition. Making the above change fixed all of the infinite loops I've found, including both of the matrices above. |
I also have confirmed that this fixes the issue! |
Using svd on certain matrices leads to an infinite loop:
The svd of some permutations of the matrix works:
For this particular matrix, any small perturbation (e.g.
m + 1e-10*rand(4,4)
) seem to work fine but there are other matrices, such aswhere
svdvals!(m2+1e-2*rand(8,8), debug=true)
often gets stuck.The problem may be related to the code linked below. If I replace
shift^2 < eps(B.dv[n1]^2)
withtrue
, the infinite loop is avoided, but I don't know if this is a proper thing to do.GenericLinearAlgebra.jl/src/svd.jl
Lines 181 to 188 in 9f9b46f
The text was updated successfully, but these errors were encountered: