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

Unable to use custom callable metric #239

Closed
tctco opened this issue Apr 4, 2023 · 2 comments
Closed

Unable to use custom callable metric #239

tctco opened this issue Apr 4, 2023 · 2 comments

Comments

@tctco
Copy link

tctco commented Apr 4, 2023

Steps to reproduce the behavior
from openTSNE import TSNE
from scipy.spatial.distance import jensenshannon

tsne = TSNE(
    perplexity=30,
    metric=jensenshannon,
    n_jobs=8,
    random_state=0,
    verbose=True,
)
embedding_train = tsne.fit(scores_list)
plot(embedding_train, ids)

The above code throws an error:

TypeError                                 Traceback (most recent call last)
Cell In[36], line 97
     88     ax.legend(handles=legend_handles, **legend_kwargs_)
     90 tsne = TSNE(
     91     perplexity=30,
     92     metric=jensenshannon,
   (...)
     95     verbose=True,
     96 )
---> 97 embedding_train = tsne.fit(scores_list)
     98 plot(embedding_train, ids)

File [~/anaconda3/envs/openmmlab/lib/python3.9/site-packages/openTSNE/tsne.py:1246](https://vscode-remote+wsl-002bubuntu-002d20-002e04.vscode-resource.vscode-cdn.net/home/tc/open-mmlab/tracker/~/anaconda3/envs/openmmlab/lib/python3.9/site-packages/openTSNE/tsne.py:1246), in TSNE.fit(self, X, affinities, initialization)
   1243 if self.verbose:
   1244     print("-" * 80, repr(self), "-" * 80, sep="\n")
-> 1246 embedding = self.prepare_initial(X, affinities, initialization)
   1248 try:
   1249     # Early exaggeration with lower momentum to allow points to find more
   1250     # easily move around and find their neighbors
   1251     embedding.optimize(
   1252         n_iter=self.early_exaggeration_iter,
   1253         exaggeration=self.early_exaggeration,
   (...)
   1256         propagate_exception=True,
...
--> 247 self.index = AnnoyIndex(data.shape[1], annoy_metric)
    249 random_state = check_random_state(self.random_state)
    250 self.index.set_seed(random_state.randint(np.iinfo(np.int32).max))

TypeError: argument 2 must be str, not function
@dkobak
Copy link
Contributor

dkobak commented Apr 4, 2023

Hmm. AFAIK this is not supposed to work like this.

You can try metric="jensen-shannon" which will call pynndescent (which you should install for this work).

@tctco
Copy link
Author

tctco commented Apr 5, 2023

Thanks for your advice!

@tctco tctco closed this as completed Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants