Skip to content

Commit

Permalink
LOBPCG not so good for smaller matrices.
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcinnes committed Oct 8, 2018
1 parent 7e29dc4 commit 43cf1a8
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions umap/spectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,21 +254,23 @@ 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,
# )
eigenvalues, eigenvectors = scipy.sparse.linalg.lobpcg(
L,
random_state.normal(size=(L.shape[0], k)),
largest=False,
tol=1e-4
)
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-8
)
order = np.argsort(eigenvalues)[1:k]
return eigenvectors[:, order]
except scipy.sparse.linalg.ArpackError:
Expand Down

0 comments on commit 43cf1a8

Please sign in to comment.