Kyle->GetThoughts();



sompy: Self-Organizing Maps implemented with scipy
16 January 2008 @ 11:28 AM MST
Current Music: Pandora
Current Mood: Has a cold
** UPDATE Mar 11, 2008:
Fixed a bug in the iterative update code:
sompy_03_11_08.zip
** END UPDATE

** UPDATE Feb 26, 2008:
There is a small bug in the code in that when using batch update you need to normalize the update values by the number of training examples before applying those changes to the nodes. Otherwise you can find yourself in a quickly escalating overcompensation problem.
Here's a fixed version:
sompy_02_26_08.zip
** END UPDATE

** UPDATE Feb 6, 2008:
This new version of the code not only wraps the map around on itself horizontally and vertically (creates a toroidal shape if you picture it three dimensionally), it also has the option (on by default) of growing by inserting a column and row into the location of the most dis-similarity in the map.
Enjoy!
sompy_grow_wrap.zip
** END UPDATE

** UPDATE Feb 1, 2008:
I found a small logic error in the original code, simply a case of improper range values (off by 1). A fixed version of the code is here: sompy_bugfix.zip
** END UPDATE

After diving into the code of SOMPython written by Paras Chopra I decided that I needed it to be more efficient for the heavy duty processing I need to do. So I started from scratch and wrote a Self-Organizing Map implementation in Python which uses scipy to do all the heavy lifting: sompy. This implementation runs about 80% faster than the enhanced version in my previous blog post.

To test my new implementation I included code that uses the Python Imaging Library (PIL) to output the result of training a map using 8 colors.

First we initialize the map randomly:
initial map

Then we begin feeding it color examples. After 50 iterations through the 8 colors we get:
map after 50 iterations

After 500 iterations:
map after 500 iterations

And after 2000 iterations:
map after 2000 iterations

This is using a 32x32 map (images uses Nearest Neighbor interpolation to produce 320x320 images). I think I'll be playing with the learning rate and neighborhood decay functions though. I think the current functions start out too slowly and then decay too rapidly. I may use a linear decay instead of the exponential decay.

I am releasing this code under the GNU GPL. All I ask in addition to that license is that you send me an email (my email address is in the source code) if you use the code for anything, just for my curiosity.

[This Entry]

Replies: 1 Comment

 On Friday, January 25th @ 02:15, Stephen said:
great work on sompy.. are you interested / available for commercial work?