eigh
稀疏和eigsh
正常 linalg 库的以下用途不应该给出相同的答案吗?
from numpy import random
from scipy.linalg import eigh as E1
from scipy.sparse.linalg import eigsh as E2
# Number of eigenvectors to check
kv = 4
# Make a symmetric matrix
N = 20
A = random.random((N,N))
A += A.T
assert( (A==A.T).all() )
L1,V1 = E1(A)
L2,V2 = E2(A,k=kv)
print sorted(L1)[::-1][:kv]
print sorted(L2)[::-1]
一些样本值:
[20.189135474050769, 3.1309586179883211, 2.6576577451888599, 2.3435647560235355]
[20.18913547405079, 3.1309586179883317, -2.9218877679802597, -3.2962262932479751]
[19.688806193598253, 3.195683848729701, 3.0987244589789058, 2.5648352930907214]
[19.688806193598261, 3.1956838487296961, 3.0987244589789014, -2.7495588013870975]
[20.482117184188727, 3.3175885619590439, 2.8910051228982252, 2.746127351510173]
[20.482117184188716, 3.3175885619590524, 2.891005122898231, 2.7461273515101809]
在我看来,内部的 Lancoz 例程只是有时会收敛。令人抓狂的是它适用于某些值 - 您可以在第三个示例中看到前四个特征值是正确的,但在其他两个示例中并非如此。
版本: Python 2.7.3
、 numpy 1.6.1
、 scipy 0.9.0
。