Hey NCA, I saw your attached image to what is “SOM neighbour Distance Plot” which is plotted using MATLAB’s “deep learning toolbox”. This figure uses the following color coding:
- The blue hexagons represent the neurons.
- The red lines connect neighboring neurons.
- The colors in the regions containing the red lines indicate the distances between neurons.
- The darker colors represent larger distances.
- The lighter colors represent smaller distances.
With the understanding of the figure, we can move onto your next question of classification of your data into the clusters. Here's an example with sample data to demonstrate the MATLAB code for identifying clusters using a “Self-Organizing Map (SOM)”:
som_grid = [1 1; 2 2; 3 3; 4 4; 5 5; 6 6; 7 7; 8 8; 9 9];
data = [1.2 1.3; 2.5 2.7; 4.1 4.4; 7.2 7.5; 8.9 8.8];
distances = pdist2(data, som_grid);
[~, bmu_indices] = min(distances, [], 2);
clusters = containers.Map;
for i = 1:length(bmu_indices)
bmu_index = num2str(bmu_indices(i));
if ~isKey(clusters, bmu_index)
clusters(bmu_index) = [];
clusters(bmu_index) = [clusters(bmu_index), i];
samples = clusters(cluster_index);
disp(['Cluster ', cluster_index, ': ', num2str(samples)]);
In this example, the “SOM grid” is a “3x3” grid with “2D” codebook vectors, and the data consists of “5” samples with “2D” features. You can modify the SOM grid and data according to your specific dataset.
Running this code will calculate the Euclidean distances between the data samples and the SOM grid, find the BMU neuron index for each sample, assign the samples to clusters based on the BMU indices, and print the samples belonging to each cluster.
Feel free to replace the sample SOM grid and data with your own data to observe the cluster assignments based on the SOM.
Hope it helps!