计算 scipy LinearOperator 的特征值时出错:“gmres 未收敛”

cil*_*lix 5 numpy linear-algebra scipy eigenvalue

我正在尝试用 Scipy 解决一个大特征值问题,其中矩阵A很密集,但我可以计算它对向量的作用,而无需A显式组装。因此,为了避免矩阵 A 变大时出现内存问题,我想使用稀疏求解器scipy.sparse.linalg.eigsLinearOperator实现此操作。

应用于eigs显式 numpy 数组A效果很好。但是,如果我改为应用eigsa LinearOperator,则迭代求解器无法收敛。即使matvec的方法LinearOperator只是与给定矩阵 的矩阵向量乘法,情况也是如此A

下面附有一个说明失败的最小示例(我使用移位反转模式,因为我对最小的几个特征值感兴趣)。A这可以很好地计算随机矩阵的特征值,但当应用于LinearOperator直接从 转换而来的a 时会失败A。我尝试摆弄迭代求解器的参数(v0ncvmaxiter)但无济于事。

我错过了一些明显的东西吗?有办法让这项工作发挥作用吗?任何建议将不胜感激。非常感谢!

编辑:我应该澄清“让这个工作”的意思(谢谢,迪特里希)。下面的示例使用随机矩阵进行说明。然而,在我的应用程序中,我知道特征值几乎是纯虚的(或者如果我将矩阵乘以 ,则几乎是纯实的1j)。我对 10-20 个最小幅度特征值感兴趣,但如果我指定 ,该算法表现不佳(即,即使对于较小的矩阵大小也不会停止)which='SM'。因此,我通过传递参数来使用移位反转模式sigma=0.0, which='LM'。我很乐意尝试不同的方法,只要它允许我计算一堆最小幅度的特征值。

from scipy.sparse.linalg import eigs, LinearOperator, aslinearoperator
import numpy as np

# Set a seed for reproducibility
np.random.seed(0)

# Size of the matrix
N = 100

# Generate a random matrix of size N x N
# and compute its eigenvalues
A = np.random.random_sample((N, N))
eigvals = eigs(A, sigma=0.0, which='LM', return_eigenvectors=False)
print eigvals

# Convert the matrix to a LinearOperator
A_op = aslinearoperator(A)

# Try to solve the same eigenproblem again.
# This time it produces an error:
#
# ValueError: Error in inverting M: function gmres did not converge (info = 1000).
eigvals2 = eigs(A_op, sigma=0.0, which='LM', return_eigenvectors=False)
Run Code Online (Sandbox Code Playgroud)

Die*_*ich 0

我尝试运行您的代码,但没有将sigma参数传递给eigs()并且它运行没有问题(请阅读eigs() 文档以了解其含义)。在你的例子中我没有看到它的好处。