Using an alternative LAPACK driver in the numpy svd method?

I use numpy.svd to compute the difference expansions of strongly conditioned matrices. For some special cases, svd will not converge and raise a Linalg.Error. I did some research and found that numpy uses the DGESDD procedure from LAPACK. The standard implementation has a hard iterative limit of 35 or something iteration. If I try to decompose the same matrix in Matlab, everything will be fine, and I think there are two reasons for this: 1. Matlab uses DGESVD instead of DGESDD, which generally seems more reliable. 2. Matlab uses an iteration limit of 75 in routine. (They changed it in the source and recompiled.)

Now the question is: is there an easy way to change the numpy backend used from DGESDD to DGESVD without having to change the numpy source?

Thanks in advance Mischa

+3
source share
2 answers

What worked for me was to simply calculate the SVD budget size of this matrix X:

U,S,V = np.linalg.svd(X, full_matrices=False)
+1
source

I'm a little late, but maybe this will help someone else ...

I had a similar problem in julia .

I found this approach from the R help list , which should work in any environment using the lapack library:

Basically, if svd (M) is not working, try svd (M ') and replace the resulting U, V accordingly.

julia:

try
  U,S,V = svd( E_restricted )
  failed = false
catch
  failed = true
end
if failed
  # try it with matrix transposed
  try
    V,S,U = svd( E_restricted' )
    failed = false
  catch
    failed = true
  end
end
if failed
  error("ERROR: svd(E) and svd(E') failed!")
end
0

All Articles