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.
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.
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?
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).
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/
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.
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.