Switch adjacency_matrix to sparse