Reputation: 5345
Is there a way, with Igraph in Python, to compute (to eventually plot) the Eigenvalue spectrum of a graph as described in the article?
http://lthiwww.epfl.ch/~leveque/Projects/barabasi_al.pdf
If so, which functions need be used? If not, what are some good alternative methods?
Upvotes: 0
Views: 2519
Reputation: 5345
Ok, so I figured out ow to do it only with igraph:
import numpy.linalg
from igraph import *
import random
import numpy as np
import time
nbr_noeuds = 50
dens = .2
p=random.uniform(dens,dens)
G = Graph.Erdos_Renyi(nbr_noeuds, p, directed=False, loops=False)
t0 = time.time()
L = G.laplacian(normalized=True)
e = numpy.linalg.eigvals(L)
print time.time()-t0
And the computation is much faster too, the print output is 0.0009
Upvotes: 2
Reputation: 25289
It's simpler and probably faster this way
In [1]: import networkx as nx
In [2]: from numpy.linalg import eigvals
In [3]: %timeit eigvals(nx.normalized_laplacian_matrix(nx.fast_gnp_random_graph(50,0.2)).A)
100 loops, best of 3: 3.13 ms per loop
Upvotes: 1