pavlin-policar / openTSNE

Extensible, parallel implementations of t-SNE
https://opentsne.rtfd.io
BSD 3-Clause "New" or "Revised" License
1.42k stars 157 forks source link

Create an affinity object with precomputed affinity matrix #216

Closed dkobak closed 1 year ago

dkobak commented 1 year ago

If I have a sparse affinity matrix stored in P, I can run openTSNE as follows:

from openTSNE import TSNE
from openTSNE.affinity import Affinities

A = Affinities()
A.P = P
Z = TSNE().fit(affinities = A)

I was wondering it would make sense to implement the following API:

Z = TSNE().fit(affinities = Affinities(P))
pavlin-policar commented 1 year ago

Hmm, the Affinities object is really meant more of as a base-class, and I never intended it to be used in this way. But I suppose there is no reason this should not work fine. There are two options, I think. One is the API you suggest Affinities(P), but I think making a new class doing basically the same thing called PrecomputedAffinities(P) would fit more nicely into the API. Since we already have the PrecomputedNeighbors KNN index. That would definitely make sense.

Since you already have a use-case in mind, would you be willing to take a crack at it?