lmcinnes / lmcinnes/umap

KeyError when using metric="precomputed"

Open
#996 1 comment 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

I am trying to use a precomputed square distance matrix when using the reducer and I am running into a strange KeyError: 'precomputed'

When I do the following:

```
reducer = umap.UMAP(n_neighbors=15, local_connectivity=1, n_components=2, metric="precomputed", random_state=0)
distance_matrix = np.random.rand(SIZE, SIZE)
output = reducer.fit_transform(distance_matrix)
```

Everything works fine.

But when I use Pytorch to create the matrix like so:

```
reducer = umap.UMAP(n_neighbors=15, local_connectivity=1, n_components=2, metric="precomputed", random_state=0)
distance_matrix = torch.randn(SIZE, SIZE).numpy()
output = reducer.fit_transform(distance_matrix)
```

I get a KeyError: 'precomputed'

What could be the potential cause of this? The memory layout of Pytorch tensors is exactly the same as that of numpy, and they are convertible to each other using the same allocated memory.

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 the reported reducer.fit_transform reproducer and compare the NumPy-generated and torch.randn(...).numpy() inputs while using metric="precomputed". Trace the precomputed-metric lookup that raises KeyError; done means both input paths behave consistently without that error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.