数日前、大きな疎行列の固有値を見つける方法について質問しました。答えが得られなかったので、考えられる解決策を説明することにしました。
One question remains:
Can I use the python implementation of ARPACK
to compute the eigenvalues of a asymmetric sparse matrix.
最初に、FOTRAN ドライバー プログラムを使用して ARPACK のサブルーチンを直接呼び出す必要はまったくないと言いたいと思います。それは非常に難しく、私はそれを実行したことがありません。しかし、次のことができます。
#オプション 1: パイソン
#numpy と scipy をインストールして、次のコードを実行できます。
import numpy as np
from scipy.linalg import eigh
from scipy.sparse.linalg import eigsh
from scipy.sparse import *
from scipy import *
# coordinate format storage of the matrix
# rows
ii = array([0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4])
# cols.
jj = array([0, 1, 0, 1, 2, 1, 2, 3, 2, 3, 4])
# and the data
data=array([1.,-1.,-1., 2.,-2.,-2., 1., 1., 1., 1., 1.])
# now put this into sparse storage (CSR-format)
m=csr_matrix( (data,(ii,jj)), shape=(5,5) )
# you can check what you did
matrix([[ 1, -1, 0, 0, 0],
[-1, 2, -2, 0, 0],
[ 0, -2, 1, 1, 0],
[ 0, 0, 1, 1, 0],
[ 0, 0, 0, 0, 1]])
# the real part starts here
evals_large, evecs_large = eigsh(m, 4, which='LM')
# print the largest 4 eigenvalues
print evals_all
# and the values are
[-1.04948118 1. 1.48792836 3.90570354]
ARPACK の非常に「よく書かれた」マニュアルを読む喜びを私たちに与えてくれるので、これは特に素晴らしいことです。
これには問題があります。非対称マトリックスでは機能しないと思います。少なくとも、結果を matlab と比較してもあまり説得力がありませんでした。
#オプション 2: MATLAB
# % put your data in a file "matrix.dat"
% row col. data
% note that indexing starts at "1"
1 1 1.
1 2 -1.
......
load matrix.dat
M = spconvert(matrix)
[v,d] = eig(M)
% v - contains the eigenvectors
% d - contains the eigenvalues
matlab を使用する方がはるかに簡単で、非対称行列で機能すると思います。さて、私は500000x500000のスパース行列を持っているので、これがmatlabで機能するかどうか....お茶の別のカップです! Python を使用すると、このサイズの行列を読み込んで、あまり問題なく固有値を計算できたことに注意する必要があります。
乾杯、