问题描述
我正在使用numpy.svd来计算条件恶劣的矩阵的奇异值分解。在某些特殊情况下,svd不会收敛并产生Linalg.Error。我进行了一些研究,发现numpy使用了LAPACK的DGESDD例程。标准实现的硬编码迭代限制为35或某些迭代。如果我尝试在Matlab中分解相同的矩阵,则一切工作正常,我认为有两个原因:
1. Matlab使用DGESVD而不是DGESDD,这通常看起来更可靠。
2. Matlab在例程中使用了75个迭代限制。 (他们在源代码中进行了更改并重新编译。)
I'm using numpy.svd to compute singular value decompositions of badly conditioned matrices. For some special cases the svd won't converge and raise a Linalg.Error. I've done some research and found that numpy uses the DGESDD routine from LAPACK. The standard implementation has a hardcoded iteration limit of 35 or something iterations. If I try to decompose the same matrix in Matlab, everything works fine, and I think there's two reasons for that:1. Matlab uses DGESVD instead of DGESDD which in general seems to be more robust.2. Matlab uses an iteration limit of 75 in the routine. (They changed it in the source and recompiled it.)
现在的问题是:是否有一种简单的方法可以将numpy中使用的后端从DGESDD更改为DGESVD,而无需修改numpy源代码?
Now the question is: Is there a simple way to change the used backend in numpy from DGESDD to DGESVD without having to modify the numpy source ?
预先感谢
Mischa
Thanks in advanceMischa
推荐答案
对我有用的是仅计算的矩阵 X
:
What worked for me was to only compute the "economy size" SVD of that matrix X
:
U,S,V = np.linalg.svd(X, full_matrices=False)
这篇关于在numpy的svd方法中使用替代LAPACK驱动程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!