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

Add knn_kwargs parameter to TSNE API #265

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

jnboehm
Copy link

@jnboehm jnboehm commented Nov 20, 2024

Issue

Discussed this with @dkobak earlier today and saw that there is already an issue present.

This PR fixes #256

Description of changes

We add knn_kwargs as a dict and pass that through to where the knn index is created. I added some parameters to Annoy (n_trees) and Pynndescent (n_trees, n_iter, max_candidates).

Includes
  • Code changes
  • Tests
  • Documentation (docstring)

Niklas Böhm added 6 commits November 20, 2024 11:31
And pass it through so the knn index gets the kwargs
Instead of hardcoding the value
parameters added: n_trees, n_iters, max_candidates
`**knn_kwargs` does not work when `knn_kwargs` is `None`, so we just
construct an empty dict in that case.
Do it in `get_knn_index` instead of TSNE
@jnboehm
Copy link
Author

jnboehm commented Nov 20, 2024

There is an exception in the Windows test somehow. I don't quite understand what the cause of that is. It mentions Windows fatal exception: access violation, which I don't think is related to what I changed.

Copy link
Owner

@pavlin-policar pavlin-policar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Jan, thanks for the PR! I've been meaning to get around to this for quite some time, so I really appreciate you taking the time to take care of this.

I do have a few comments though before merging.

openTSNE/affinity.py Show resolved Hide resolved
openTSNE/nearest_neighbors.py Outdated Show resolved Hide resolved
openTSNE/nearest_neighbors.py Outdated Show resolved Hide resolved
openTSNE/nearest_neighbors.py Outdated Show resolved Hide resolved
@pavlin-policar
Copy link
Owner

The failing windows tests likely have nothing to do with your changes, it's probably just standard CI problems that will go away in future runs...

@jnboehm
Copy link
Author

jnboehm commented Nov 21, 2024

I'm working on it now, but I noticed that the classes also have a __setstate__ method (for pickling if I am not mistaken?). Unfortunately, I do not really know how that would interact with the knn_kwargs, or is that unrelated?

Niklas Böhm added 4 commits November 21, 2024 16:55
Now the knn_kwargs are not splatted.  This way it is easier to pass in
custom parameters that will then be pass through to the underlying
class.
Added it to two more classes, FixedSigmaNN and Uniform.
After popping the `n_trees` parameter from it, which needs to go into
`index.build()`.
@jnboehm
Copy link
Author

jnboehm commented Nov 26, 2024

Should I also add some tests for this? I'm not sure how exactly they should look, but I'd guess that they should create a TSNE object with a nonempty knn_kwargs parameter. Would this already check if it can be properly pickled through __setstate__ and related functionality? To be honest, the test logic looks a bit mysterious to me and I am not really familiar with it, unfortunately.

@pavlin-policar
Copy link
Owner

Hey Jan, yes, some tests would definitely be nice to check that things are working as intended. That would probably involve patching the NN indices and making sure they were, indeed, called with the correct knn_kwargs parameter, then going through all possible ways to actually call this method.

Looking at the code, pickling should work out of the box, since all class attributes should be saved here. Ideally, you'd add a test that checks this too. Looking at the tests, however, I wasn't very good at adding tests for pickling. I would add it to the KNNIndexTestMixin class, so that it runs for all the different NN index types.

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

Successfully merging this pull request may close these issues.

Allow KNNIndex classes to take **kwargs arguments and pass them to KNN library
2 participants