3

I am trying to use t-SNE with Wasserstrain distance instead of Euclidean. Here is part of my code:

from sklearn.manifold import TSNE
from scipy.stats import wasserstein_distance

tsne = TSNE(n_components=2,perplexity=40, n_iter=1000, metric=wasserstein_distance)
img_embedded = tsne.fit_transform(images)

images contains 512 images which are 64x64x3. Can someone please tell me if my code actually does what I want? I am not sure if that metric=wasserstein_distance is correct. The code works just fine, but when I look into the 2D space, it looks horrible. If I use the Euclidean metric, the 2D image is reasonably good, so I am not sure if the Wasserstrain distance is simply not suitable for my problem, or if I am implementing it the wrong way. Thank you!

Edit: The images are of a fixed size object, moving on a fixed background. Ideally, given that for each image everything is the same, except for the position of the object, I would hope that the 2D representation would show the trajectory of the object i.e. the x and y of the object in each image (or at least some invertible transformation of them). Below I attached the image obtained using the Euclidian distance (first one) and Wasserstein distance (second one). As you can see, in the first case the trajectories are pretty clear (for example lines are mostly intersecting where they are supposed to, so topology is mostly preserved). In the second case there is a total mess.

enter image description here

enter image description here

Silviu
  • 749
  • 3
  • 7
  • 17
  • What is the problem you are trying to solve? Please also add the resulting 2D images and describe briefly what is horrible/good about them. Finally, it would be awesome if you could generate some toy data within the example code to make it reproducible. – MB-F Sep 11 '19 at 05:16
  • Here is an answer which explains why the Wasserstein distance is not a good idea: https://stats.stackexchange.com/questions/355238/why-kullback-leibler-in-stochastic-neighbor-embedding – mss Aug 09 '23 at 10:01

0 Answers0