lmcinnes / lmcinnes/umap

precomputed_knn error

Open
#1,012 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
8.3k
Forks
871
Avg merge
1d 13h
Merged PRs (30d)
5

Description

api documentation here https://umap-learn.readthedocs.io/en/latest/api.html tells :

" If you wish to use k-nearest neighbors data calculated by another package then provide a tuple of the form (knn_indices, knn_dists). The contents of the tuple should be two numpy arrays of shape (N, n_neighbors) where N is the number of items in the input data. The first array should be the integer indices of the nearest neighbors, and the second array should be the corresponding distances. The nearest neighbor of each item should be itself, e.g. the nearest neighbor of item 0 should be 0, the nearest neighbor of item 1 is 1 and so on. Please note that you will not be able to transform new data in this case. "

If you provide such an input to umap api it raises this error during fit :

File /opt/conda/lib/python3.10/site-packages/umap/umap_.py:2288, in UMAP.fit(self, X, y)
2286 self.knn_indices = self.precomputed_knn[0]
2287 self.knn_dists = self.precomputed_knn[1]
-> 2288 self.knn_search_index = self.precomputed_knn[2]
2290 self._validate_parameters()
2292 if self.verbose:

IndexError: tuple index out of range

if this input is provided (knn_indices, knn_dists,None) it raises :

File /opt/conda/lib/python3.10/site-packages/umap/umap_.py:2290, in UMAP.fit(self, X, y)
2287 self.knn_dists = self.precomputed_knn[1]
2288 self.knn_search_index = self.precomputed_knn[2]
-> 2290 self._validate_parameters()
2292 if self.verbose:
2293 print(str(self))

File /opt/conda/lib/python3.10/site-packages/umap/umap_.py:1930, in UMAP._validate_parameters(self)
1925 raise ValueError(
1926 "precomputed_knn[0] and precomputed_knn[1]"
1927 " must be numpy arrays of the same size."
1928 )
1929 if not isinstance(self.knn_search_index, NNDescent):
-> 1930 raise ValueError(
1931 "precomputed_knn[2] (knn_search_index)"
1932 " must be an NNDescent object."
1933 )
1934 if self.knn_dists.shape[1] < self.n_neighbors:
1935 warn(
1936 "precomputed_knn has a lower number of neighbors than "
1937 "n_neighbors parameter. precomputed_knn will be ignored"
1938 " and the k-nn will be computed normally."
1939 )

ValueError: precomputed_knn[2] (knn_search_index) must be an NNDescent object.

Is the documentation right ? Can we really provide precomputed_knn from other packages ?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with UMAP.fit and _validate_parameters in umap/umap_.py, then compare their handling of the documented precomputed_knn tuple with the API documentation. Reproduce the two errors using two- and three-element tuples; done means the documented input format and fit-time validation agree.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.