ToroidalSOM

A Kohonen map fit to some synthetic data on a torus. On the left the torus has been cut up and laid out into a flat sheet. Blue scatter plot is the training data, red dots are the map. On the right is the same plot without cutting and rolling out th…

A Kohonen map fit to some synthetic data on a torus. On the left the torus has been cut up and laid out into a flat sheet. Blue scatter plot is the training data, red dots are the map. On the right is the same plot without cutting and rolling out the torus, and with a mesh of the torus included.

Lately I've been looking into methods of non-linear dimensionality reduction, especially on the torus. My preoccupation with making toroidal versions of various analysis approaches stems from the fact that I study locomotion and limbs go through cycles. Things that go through cycles can be parameterized by how far through that cycle they are, with 0% and 100% being the same thing. So if you have two legs then you have two such cycling numbers describing how the limbs are configured, and that makes a torus.

One approach to dimensionality reduction I've been getting into is self-organizing or Kohonen maps. These work by setting up a low dimensional map that is to be used as a proxy or model of some data in a higher dimensional space. They are fit by taking a training example and moving the nearest bits of the map a bit closer. Do this a large number times and slowly reduce how much of the map you move each time and eventually the map ends up on top of the data.

There exist a few places you can obtain software to do this, but I had a problem. I wanted to do this for data on a torus, which means I needed to be able to change what was meant by 'distance' in the space. Something that is 1% through a cycle is 2% away from something that is at 99%, not 98%. Since the algorithm for Kohonen maps is pretty straightforward I elected to write my own. At present this fits a 1D map, but you can supply a metric for any dimension of input space (I provide a metric for the 2D torus and the 3D induced metric from my publications on gait transitions and stability in dogs).

The example you see here is for some data scattered on a 2-torus. On the left I've cut open and spread out the torus so the top and bottom edge of the plots are the same, as are the left and right edges . The blue scatter plot is the training data, the red dots are the self-organizing map. If things were working well the red dots would lie inside the blue following the general pattern of the data, which they do. On the right is the same plot but without cutting and rolling out the torus. The turquoise mesh is the torus.

Code is fully documented with Epydoc, includes a usage example, the usual gubbins.

This work was completed with support from the Royal Veterinary College

Link to the github.