t-SNE using earth mover distance metric

329 views Asked by At

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

0

There are 0 answers