Code covered by the BSD License

Highlights from Self-Organizing Map - Simple demonstration

4.0
4.0 | 1 rating Rate this file 50 Downloads (last 30 days) File Size: 2.68 KB File ID: #39930

Self-Organizing Map - Simple demonstration

George Azzopardi (view profile)

A simple and neat implementation of a self-organizing map algorithm

File Information
Description

While there are many sources that provide the pseudo-code of a self-organizing map (SOM), I could not find a simple implementation that clarifies every step of this algorithm which was introduced by Kohonen.

For this reason I implemented this clearly defined Matlab implementation and wanted to share it with you.

As a demonstration I use the RGB 3D training vectors. The trained SOM neurons result in a 2D spatial arrangement such that the neurons that have similar 3D weight vectors (i.e. similar colour representation) are located close to each other.

Required Products Image Processing Toolbox
MATLAB
MATLAB release MATLAB 7.9 (R2009b)
19 Jul 2014 George Azzopardi

George Azzopardi (view profile)

I guess the problem is with the imagesc function. It expects the values to be between 0 and 1. You can try to divide with the maximum value before calling the imagesc function.

Comment only
19 Jul 2014 sam

sam (view profile)

I have question : if I want to feed the SOM with my input and the input are integer.

% Generate random training data
trainingData = rand(ntrainingvectors,nfeatures) * 10 ; <----- int values

it does not accept that and complain.

************************************************************
Error using image
TrueColor CData contains element out of range 0.0 <= value <= 1.0

Error in imagesc (line 19)
hh = image(varargin{1},'CDataMapping','scaled');

Error in SOMSimple>displaySOMmap (line 127)
imagesc(sommap(:,:,1:3));

Error in SOMSimple (line 100)
displaySOMmap(fig, 2, ['Epoch: ',num2str(t),'/',num2str(nepochs),', Training
Vector: ',num2str(ntraining),'/',num2str(ntrainingvectors)], som, nfeatures);

Error in SOMSimpleMain (line 36)
SOMSimple(3,60,10,100,0.1,0.05,20,0.05,2)
**********************************************************
what is the solution?

Comment only
05 Nov 2013 ben harrison

ben harrison (view profile)

I'm probably missing something, but the SOM Toolbox (a MATLAB library under the GNU GPL) was written by Kohonen's colleagues and students, and contains what might be described as the 'official' implementation of the algorithm, many visualisations, etc. http://www.cis.hut.fi/somtoolbox/.

The 2000 paper/tutorial by Juha Vesanto also provides a detailed description of the implementation (Vesanto, 2000. Neural network tool for data mining: SOM Toolbox, same website as above).

Comment only
25 Jun 2013 George Azzopardi

George Azzopardi (view profile)

Could you write the Matlab command that you are using to call the SOMSImple function?

I suggest that you read the article called "Self-Organizing Map-Based Color Image Segmentation with k-Means Clustering and Saliency Map" which you can find in http://www.hindawi.com/isrn/sp/2011/393891/

Comment only
25 Jun 2013 Lim

Lim (view profile)

I have this 'rather' big RGB image of 960 x 1280 pixels. Actually I have trouble preparing the image for SOM, as few attempts I tried on different SOM codes, it has error of 'out of memory' which I assume either the image has too much data for SOM to process or I prepared it wrongly. The purpose I want to try SOM is for image segmentation purpose.

Comment only
24 Jun 2013 George Azzopardi

George Azzopardi (view profile)

Hi Lim, could you kindly elaborate further on your question? An SOM is a unsupervised clustering method which can be used for dimensionality reduction. In thsi simple example I am initializing a matrix of 3D neurons such that I can show them as RGB values. I wish you can be more specific such that I can help you better.

Comment only
24 Jun 2013 George Azzopardi

George Azzopardi (view profile)

Oops, I wanted to write: "... elaborate further on your question?"

Comment only
24 Jun 2013 Lim

Lim (view profile)

Hi. May I know how can I test this code on my own image please?

Comment only
11 Feb 2013 Afshin Abbasi