View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Self-Organizing Map - Simple demonstration

4.0 | 1 rating Rate this file 39 Downloads (last 30 days) File Size: 2.68 KB File ID: #39930 Version: 1.0
image thumbnail

Self-Organizing Map - Simple demonstration



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

| Watch this File

File Information

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 release MATLAB 7.9 (R2009b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (9)
19 Jul 2014 George Azzopardi

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)

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)
what is the solution?

Comment only
05 Nov 2013 ben harrison

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.

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

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

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

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

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

Contact us