Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No need to check or require a symmetrical sparse matrix if the kNN s precomputed #1157

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions umap/umap_.py
Original file line number Diff line number Diff line change
Expand Up @@ -2480,18 +2480,19 @@ def fit(self, X, y=None, force_all_finite=True, **kwargs):
print(ts(), "Construct fuzzy simplicial set")

if self.metric == "precomputed" and self._sparse_data:
# For sparse precomputed distance matrices, we just argsort the rows to find
# nearest neighbors. To make this easier, we expect matrices that are
# symmetrical (so we can find neighbors by looking at rows in isolation,
# rather than also having to consider that sample's column too).
# print("Computing KNNs for sparse precomputed distances...")
if sparse_tril(X).getnnz() != sparse_triu(X).getnnz():
raise ValueError(
"Sparse precomputed distance matrices should be symmetrical!"
)
if not np.all(X.diagonal() == 0):
raise ValueError("Non-zero distances from samples to themselves!")
if self.knn_dists is None:
# For sparse precomputed distance matrices, we just argsort the rows
# to find nearest neighbors. To make this easier, we expect matrices
# that are symmetrical (so we can find neighbors by looking at rows
# in isolation, rather than also having to consider that sample's
# column too).
# print("Computing KNNs for sparse precomputed distances...")
if sparse_tril(X).getnnz() != sparse_triu(X).getnnz():
raise ValueError(
"Sparse precomputed distance matrices should be symmetrical!"
)
self._knn_indices = np.zeros((X.shape[0], self.n_neighbors), dtype=int)
self._knn_dists = np.zeros(self._knn_indices.shape, dtype=float)
for row_id in range(X.shape[0]):
Expand Down
Loading