You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, is there a way to use k-nearest neighbors data created externally? My current strategy is to create a dummy class of the form:
classPrecomputedKNNIndex:
def__init__(self, indices, distances):
self.indices=indicesself.distances=distancesself.k=indices.shape[1]
defbuild(self):
returnself.indices, self.distancesdefquery(self, query, k):
raiseNotImplementedError("No query with a pre-computed knn")
defcheck_metric(self, metric):
ifcallable(metric):
passreturnmetric
and use it like:
importopenTSNEperplexity=30data=get_data_fom_somewhere()
n_neighbors=min(data.shape[0] -1, int(3*perplexity))
# assume this doesn't return the "self" neighbor as the first item in the knnindices, dists=get_nn_from_somewhere(data, n_neighbors)
knn=PrecomputedKNNIndex(indices, dists)
affinities=openTSNE.affinity.PerplexityBasedNN(
perplexity=perplexity,
knn_index=knn,
)
embedder=openTSNE.TSNE(n_components=2)
embedded=embedder.fit(data, affinities=affinities)
This seems to work perfectly well, just wondered if I am missing a more obvious approach.
The text was updated successfully, but these errors were encountered:
Hey, I think this is currently the only approach that would work. Your dummy class is actually included here, and I think it has already been released (it's been a while since I looked at this).
It's a convoluted solution, I know, but currently the only supported one. I need to return to this and think about how I would allow something like the standard metric="precomputed" without cluttering the API further.
Oh yes looks like I missed the in-built precomputed class. Works for me.
Although I am sure you are not looking for API suggestions, maybe you could allow the neighbors parameter on the TSNE constructor to take a tuple containing the indices and distances and then either create the affinities via the perplexity parameter, or use the Uniform version if the perplexity=None?
Hello, is there a way to use k-nearest neighbors data created externally? My current strategy is to create a dummy class of the form:
and use it like:
This seems to work perfectly well, just wondered if I am missing a more obvious approach.
The text was updated successfully, but these errors were encountered: