Home C++ Lua GitHub Games Math Myself Contact



GPU Kohonen Map

I am working on a GPU based Recurrent Network. Coding demos is taking me some time. I have to go way out of my way and learn about things like reinforcement learning and policy gradients and stuff like that. A lot that I didn't really plan on signing on for. All I wanted to do was take an O(n^3) operation algorithm and rewrite it in a massively parallel manner for the GPU.

After a year of working on the project I got a bit frustrated with the lack of reward. So, as instant-gratification-driven as I am, I went out of my way and looked up a few other GPU/AI/biological computing concepts that I could implement as well. I stumbled across a Kohonen map. I might've had an alternative motivation. I remember I had never coded one up before and had been curious on how they worked.

I coded up a purely software version in Lua. After observing how linearizable the process was I shortly coded up a GLSL one for my GL Lua Shell. This makes for the first program that I got to write an O(log(n)) GPU search algorithm. Something I've wanted to do for a while now.

Of course someone else had already beat me to it.

The CPU version attempts to fit a sheet to a Gaussian curve surface. I remember coding up a 1D example at first. I forget how modifyable the code is to get back to that state.

The GPU version attempts to fit a 16x16 array of colors to the colorspace of a provided picture. The equivalent of an image color reduction. This one starts off not running. You'll have click the 'doUpdate' button to start the process. From there you can adjust the sliders to watch the color convergence and what not. All colorspace display is brought to your courtesy of vertex and pixel buffer objects.

By default the init.lua file points to som-gpu.lua, the GPU version. To run the CPU version simply switch the Lua require command from 'som-gpu' to 'som' and all should work out.

Some day I will get drag-and drop support for loading images into the GL Lua Shell. I believe it's already there for a certain texture widgets in the Windows version. More on that to come.

Download the Script Here
Source Code Dependencies OpenGL Lua Shell