2

I'm trying to compute the second smallest eigenvalue of the laplacian matrix of a complex network(with 10000 nodes) with python using the shift-invert mode, here is the code:

import numpy as np
import networkx as nx
from scipy import sparse
G = nx.watts_strogatz_graph(10000,4,0.1)
degree_dict = nx.degree(G)
degree_list = []
for i in degree_dict:
    degree_list.append(degree_dict[i])
lap_matrix = sparse.diags(degree_list, 0)-nx.adjacency_matrix(G)
eigval, eigvec = sparse.linalg.eigsh(lap_matrix, 2, sigma=0, which='LM')
second_eigval = eigval[1]

when running above code, i got:

RuntimeError: Factor is exactly singular

Does the error mean the laplacian matrix is singular? Any ideas as to how I should proceed? Is there any other way to compute this second smallest eigenvalue(with Matlab or any other programming language)?

paisanco
  • 4,098
  • 6
  • 27
  • 33

1 Answers1

2

Your code works for me (SciPy 1.0.0) almost exactly as written, except I simplified the formation of degree_list (which threw a KeyError in your version)

import numpy as np
import networkx as nx
from scipy import sparse

G = nx.watts_strogatz_graph(10000,4,0.1)
degree_dict = nx.degree(G)
degree_list = [x[1] for x in degree_dict]
lap_matrix = sparse.diags(degree_list, 0)-nx.adjacency_matrix(G)
eigval, eigvec = sparse.linalg.eigsh(lap_matrix, 2, sigma=0, which='LM')

Now eigval is [1.48814294e-16, 4.88863211e-02]; the smallest eigenvalue is zero within machine precision but the second smallest is not.