I have some data reduced by TSNE into a 2D representation, which shows clear spatial features.

2D data organized by TSNE

However, I'd like to format this into a grid – not just snapping data to the nearest grid square but spreading everything out to fill up a grid, preserving (as much as possible) the existing spatial relationships.

So far, I've only found this article which might close to what I need? This process might already have a name and I'm just one step from an easy Google solution, but at the moment I'm stuck!

  • $\begingroup$ What do you hope to accomplish by doing this? $\endgroup$
    – Emre
    Jan 24 '17 at 1:30
  • $\begingroup$ @Emre – see my answer below for images of the result. I wanted to do something similar to cs.stanford.edu/people/karpathy/cnnembed but for text. $\endgroup$ Jan 24 '17 at 13:35

There seem to be a few options, but I found rasterfairy which is very easy to install and use. Has the added bonus of being able to fit to a rectangular grid, but also circular and other arbitrary shapes.

A very nice IronPython notebook example: https://github.com/Quasimondo/RasterFairy/blob/master/examples/Raster%20Fairy%20Demo%201.ipynb

And some example results:

tsne before gridding

gridded tsne

  • $\begingroup$ Looks like it dosen't have python 3 support. What a shame $\endgroup$ Feb 7 '19 at 7:06
  • $\begingroup$ My lab made a fork of this library with identical API and python 3 support. Just pip install yale-dhlab-facenet. pypi.org/project/yale-dhlab-facenet $\endgroup$
    – duhaime
    Sep 23 '19 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.