问题描述
我想在Python中找到稀疏矩阵的N个最小特征值.我尝试使用scipy.sparse.linalg.eigen.arpack
包,但是在计算最小特征值时非常慢.我在某处读到有移位反转模式,但是当我尝试使用它时,收到一条错误消息,告诉我还不支持移位反转模式.关于我应该如何进行的任何想法?
I'd like to find the N smallest eigenvalues of a sparse matrix in Python. I've tried using the scipy.sparse.linalg.eigen.arpack
package, but it is very slow at computing the smallest eigenvalues. I read somewhere that there is a shift-invert mode, but when I try using it, I receive an error message telling me that the shift-invert mode is not yet supported. Any ideas as to how I should proceed?
推荐答案
SciPy版本
比较 scipy.sparse.linalg.eigs
(来自SciPy v0.9 ),其文档为的.eigs.html#scipy.sparse.linalg.eigs"rel =" noreferrer> scipy.sparse.linalg.eigs
看来,移位反转模式自v0.10起便已实现并正常工作.具体来说,v0.9文档中对sigma
参数的解释指出该参数尚未实现,但v0.10文档并未表明是这种情况.
SciPy Versions
如果您没有SciPy v0.10或更高版本,则安装最新版本应该可以使您使用稀疏特征求解器的移位反转模式.
如问题中所述,可以使用ARPACK接口查找小幅度特征值.这是通过在调用scipy.sparse.linalg.eigs
时传递which='SM'
来完成的.但是,正如问题中所述,它很慢.在 ARPACK的稀疏特征值问题,其中指出:
实验
让我们看一些代码,尝试将shift-invert与SciPy的v0.9和v0.10一起使用.在这两种情况下,我们都将使用以下代码.
Experiments
from scipy.sparse import identity
from scipy.sparse.linalg import eigs
A = identity(10, format='csc')
A.setdiag(range(1, 11))
eigs(A, 3, sigma=0) # find three eigenvalues near zero using shift-invert mode
SciPy v0.9
SciPy v0.9
Running the code in SciPy v0.9 results in an exception being raised.
NotImplementedError: shifted eigenproblem not supported yet
SciPy v0.10
SciPy v0.10
Running the code in SciPy 0.10 produces expected results.
(array([ 1.+0.j, 2.+0.j, 3.+0.j]),
array([[ -1.00000000e+00+0.j, 5.96300068e-17+0.j, 9.95488924e-17+0.j],
[ 3.55591776e-17+0.j, 1.00000000e+00+0.j, -4.88997616e-16+0.j],
[ -3.79110898e-17+0.j, 1.16635626e-16+0.j, 1.00000000e+00+0.j],
[ -1.08397454e-17+0.j, 1.23544164e-17+0.j, 1.78854096e-15+0.j],
[ 1.68486368e-17+0.j, -9.37965967e-18+0.j, 2.05571432e-16+0.j],
[ -2.97859557e-19+0.j, -3.43100887e-18+0.j, 3.35947574e-17+0.j],
[ 1.89565432e-17+0.j, -3.61479402e-17+0.j, -1.33021453e-17+0.j],
[ -1.40925577e-18+0.j, 3.16953070e-18+0.j, 7.91193025e-17+0.j],
[ 6.76947854e-19+0.j, -3.75674631e-19+0.j, 3.61821551e-17+0.j],
[ -3.07505146e-17+0.j, -6.52050102e-17+0.j, -8.57423599e-16+0.j]]))
这篇关于用Python计算稀疏矩阵的N个最小特征值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!