LOBPCG not so good for smaller matrices.
@@ -254,20 +254,22 @@ def spectral_layout(data, graph, dim, random_state, metric="euclidean", metric_k
k = dim + 1
num_lanczos_vectors = max(2 * k + 1, int(np.sqrt(graph.shape[0])))
try:
- # eigenvalues, eigenvectors = scipy.sparse.linalg.eigsh(
- # L,
- # k,
- # which="SM",
- # ncv=num_lanczos_vectors,
- # tol=1e-4,
- # v0=np.ones(L.shape[0]),
- # maxiter=graph.shape[0] * 5,
- # )
+ if L.shape[0] < 2000000:
+ eigenvalues, eigenvectors = scipy.sparse.linalg.eigsh(
+ L,
+ k,
+ which="SM",
+ ncv=num_lanczos_vectors,
+ tol=1e-4,
+ v0=np.ones(L.shape[0]),
+ maxiter=graph.shape[0] * 5,
+ )
+ else:
eigenvalues, eigenvectors = scipy.sparse.linalg.lobpcg(
L,
random_state.normal(size=(L.shape[0], k)),
largest=False,
- tol=1e-4
+ tol=1e-8
)
order = np.argsort(eigenvalues)[1:k]
return eigenvectors[:, order]
