Tuesday, November 20, 2012

speed up sparse eigen value computing

scipy, octave, R, matlab all call arpack backend.

I focus on scipy syntax here. Others should be similar.

If all the eigen values are non-negative, and smallest eigen values are desired. Use following code to speed up.

ev, ef = sparse.linalg.eigsh(A, k = 6, M, sigma=0.0, which = 'LM')


Here is the test result
>>> t = time.time();ev, ef = sparse.linalg.eigsh(W, 20, S, sigma=0.0, which = 'LM');print (time.time() - t)
0.0778040885925
>>> t = time.time();ev, ef = sparse.linalg.eigsh(W, 20, S, which = 'SM');print (time.time() - t)
0.231815099716
>>>
where W and M are 642 by 642 square matrices.

No comments:

Post a Comment