I do not have an answer to your question Alejandro, but I am curious about why the timing
changes each time the code is executed. Is there any random allocation in the process of solving
your problem?

Sergio

 

 



---------------------------------------------------------------------- 

Message: 1 
Date: Wed, 23 May 2012 09:33:15 -0600 
From: Alejandro Weinstein <alejandro.weinstein@gmail.com> 
Subject: [SciPy-User] scipy.sparse.linalg.eigs is faster with k=8 than 
	with	k=1 
To: scipy-user@scipy.org 
Message-ID: 
	<CAPFc=oz+ck-_6msNQ7SadNb69RH9zwTgKSj1U0PfdsckH5vydA@mail.gmail.com> 
Content-Type: text/plain; charset=ISO-8859-1 

Hi: 

I am using scipy.sparse.linalg.eigs with a 336x336 sparse matrix with 
1144 nonzero entries. I only need the eigenvector corresponding to the 
larger eigenvalue, so I was running the function with k=1. However, I 
found that it is about 10 times faster to call the function with k=8. 

I am testing this with the following code (available here: 
https://gist.github.com/2775892): 

############################################################# 
import timeit 

setup = """ 
import numpy as np 
import scipy.sparse 
import scipy.io 
from scipy.sparse.linalg import eigs 

P = scipy.io.mmread('P.mtx') 
""" 

n = 10 
for k in range(1,20): 
    code = 'eigs(P, k=%d)' % k 
    t = timeit.timeit(stmt=code, setup=setup, number=n) / n 
    print 'k: %2d, time: %5.1f ms' % (k, 1000*t) 

############################################################# 

The output is 

k:  1, time: 301.7 ms 
k:  2, time: 242.6 ms 
k:  3, time: 352.0 ms 
k:  4, time: 168.8 ms 
k:  5, time: 148.1 ms 
k:  6, time:  93.2 ms 
k:  7, time:  70.0 ms 
k:  8, time:  29.3 ms 
k:  9, time:  45.2 ms 
k: 10, time:  63.0 ms 
k: 11, time: 209.1 ms 
k: 12, time: 170.8 ms 
k: 13, time: 120.2 ms 
k: 14, time: 104.6 ms 
k: 15, time: 115.0 ms 
k: 16, time:  97.0 ms 
k: 17, time:  94.0 ms 
k: 18, time:  94.4 ms 
k: 19, time:  74.3 ms 

Is this behavior typical for eigs? In other words, should I always use 
k set to values around 6 or 8, or is it matrix dependent? 

I am also curious about this. I would expect that computing 1 
eigenvector should never be slower than computing more eigenvectors. 
Any about why is this happening? 

Alejandro. 


------------------------------