Multicore-TSNE icon indicating copy to clipboard operation
Multicore-TSNE copied to clipboard

other metrics

Open chupvl opened this issue 7 years ago • 10 comments

Hi!

is it possible to add other metrics, some data are not well suited for default 'euclidean' one?

Many thanks!

chupvl avatar Jun 22 '17 09:06 chupvl

Hi, as far as I know quadtree is only suited for euclidean. You can get cosine for free by normalizing your data first. Other metrics are not supported.

DmitryUlyanov avatar Jun 25 '17 19:06 DmitryUlyanov

Now it is possible to easily add new metrics (yet in C++ with recompilation). If you have any preferences I could implement some.

DmitryUlyanov avatar Dec 23 '17 13:12 DmitryUlyanov

@DmitryUlyanov why quadtree is only suited for euclidean? If I just change a distance function when you instantiate VpTree<> from euclidean to cosine will it be sufficient?

asanakoy avatar Dec 23 '17 18:12 asanakoy

Hi @asanakoy, my statement from 25 June was incorrect.

If I just change a distance function when you instantiate VpTree<> from euclidean to cosine will it be sufficient?

Now I realize that it is not that easy. Distance should also be changed in gradient computation and for now it is hardcoded to be euclidean.

DmitryUlyanov avatar Dec 23 '17 20:12 DmitryUlyanov

Well, you still can get cosine similarity by normalizing your data to have unit norm.

DmitryUlyanov avatar Dec 23 '17 20:12 DmitryUlyanov

Now I realize that it is not that easy. Distance should also be changed in gradient computation and for now it is hardcoded to be euclidean.

Could you please point out which line of code it is?

asanakoy avatar Dec 23 '17 20:12 asanakoy

Well, you still can get cosine similarity by normalizing your data to have unit norm.

But this is not exactly the same as the cosine distance.

asanakoy avatar Dec 23 '17 20:12 asanakoy

I have added not normalized cosine distance (basically it is dot product) in my fork https://github.com/asanakoy/Multicore-TSNE/commit/eebf7365e5f75ec772acb6212a47eef8d5aef0f6

But as you mentioned above it's not fully correct because I forgot to change the gradient computation.

asanakoy avatar Dec 23 '17 20:12 asanakoy

Could you please point out which line of code it is?

https://github.com/DmitryUlyanov/Multicore-TSNE/blob/master/multicore_tsne/tsne.cpp#L242 https://github.com/DmitryUlyanov/Multicore-TSNE/blob/master/multicore_tsne/tsne.cpp#L313

Maybe there are more.

But this is not exactly the same as the cosine distance.

I see, but if we used squared euclidean distance than it is. Looks easy to change in the code :)

By the way, both cosine distance and squared euclidean are not proper distances. This repo actually uses squared euclidean for VP tree by default and it seem to work well, but maybe there are cases where it breaks the method.

DmitryUlyanov avatar Dec 23 '17 21:12 DmitryUlyanov

I have investigated the implementation more carefully.

VPTree works with any metric distance. And it can work well with angular distance (arccosine distance) as it is pseudo metric. No need to change a gradient calculation as the new distance function is only appplied in the original space. The distance in the target embedding space is euclidean.

I have implemented several different distance metrics + added lots of comments about implementation in my fork https://github.com/asanakoy/Multicore-TSNE.

asanakoy avatar Jan 18 '18 21:01 asanakoy