The idea: a grid of neurons that is stretched over the data

A self-organizing map (SOM, or Kohonen map, after Teuvo Kohonen) learns without labels. It has a fixed grid of neurons; here 5 × 5 = 25. Each neuron has a weight vector w, which is a point in the same space as the data. For each sample, the neuron with the nearest weight vector wins, and it and its grid neighbours move toward the sample. Over many samples the grid spreads over the data like a net, and neurons that are close on the grid end up close in the data.

Left: the grid space, a 5 by 5 lattice of cells with the best matching unit dark blue and rings of lighter blue around it for its neighbours. Right: the data space, the same neurons as dots joined by grid lines, a red sample x, and arrows from the winner and its neighbours toward x, longer arrows for closer grid neighbours
Two spaces: the grid decides who learns and how much (h); the data space is where the weights move.

The page has 36 points in a square. The coloured dots are the 25 weight vectors; one colour per grid column, and the grey lines join grid neighbours. The panel on the right is the grid itself, which never moves.

Step 1: the best matching unit

Take one sample x. Measure the distance from x to every weight vector. The nearest neuron is the best matching unit (BMU). This is the same rule as the assignment step of K-Means, for one point. In Demo 1 the first sample is x = (6.88, 7.92); the BMU is neuron (2, 1) at distance 2.54.

Step 2: the neighbourhood is measured on the grid

Every neuron gets a share h of the pull, from its distance d to the BMU on the grid: h = exp(−d² / 2σ²). The BMU has h = 1. With radius σ = 2.5 a grid neighbour gets 0.92 and a neuron two cells away 0.73, so at the start almost the whole grid moves together. With σ = 0.3 a neighbour gets 0.004: only the winner learns.

Step 3: everyone moves toward the sample

Each weight vector moves part of the way to x: w ← w + α·h·(x − w). The learning rate α says how far; α = 0.5 means the BMU goes half way. Because grid neighbours are dragged along, neurons that are next to each other on the grid stay next to each other in the data. That is the "map" part: the grid's order is kept, which is called topology preservation.

Shrinking α and σ

Training runs 10 epochs; each one shows all 36 points once in a new shuffled order, so there are 360 updates (t = 0 … 359). Both α and σ fall in a straight line with t:

t090180270359
learning rate α0.5000.3800.2600.1400.021
radius σ (start 2.5)2.501.951.400.850.31

Early on, a wide radius and a big step put the grid in the right order: the ordering phase. Later, a small radius and a small step let each neuron settle near its own patch of data: the fine-tuning phase.

Three snapshots of the grid over the 36 points. Start: all 25 weight vectors crumpled in a small square in the middle. After epoch 1: the grid has opened but is uneven. After epoch 10: a flat net spread over the whole square with every column colour in order
Demo 2: the crumpled start opens in the first epoch, then spreads into a flat, ordered net.

Two ways to measure a map

MeasureWhat it countsGood value
quantization error (QE)mean distance from a sample to its BMUsmall: the neurons sit near the data
topographic error (TE)share of samples whose nearest and second-nearest neurons are not grid neighboursnear 0: the grid's order matches the data

In Demo 2 QE falls from 2.042 to 0.749 and TE from 0.972 to 0.028. The page also counts folded cells: grid squares that are flipped compared with the rest of the net (0 of 16 here).

QE alone can fool you. In Demo 3 σ stays at 0.3, so only the BMU learns. That is online K-Means (competitive learning): QE ends at 0.740, even lower than Demo 2, but TE is 1.000. Every sample's two nearest neurons are far apart on the grid, so the grid tells you nothing.

A twist can freeze in

The order is set early, while σ is wide. In Demo 4 the grid starts flat but twisted: rows 0 and 1 run right to left. With σ starting at 1.0, the pull never reaches far enough to swing those rows around, and as σ shrinks the fold is locked in: 7 of 16 cells stay folded, TE = 0.139. Demo 5 starts from the same twist with σ = 2.5: the early updates move half the grid at once and the fold irons out (0 folded cells, TE = 0.028).

Three grids over the square. Twisted start: the bottom two rows have their column colours reversed and the grid lines cross. After training with sigma starting at 1.0: the crossing is still there, 7 folded cells. After training with sigma starting at 2.5: a flat ordered net, 0 folded cells
The radius has to be wide at the start: a small σ cannot undo a fold, it only tightens it.

Neurons in a gap

In Demo 6 the points form two bands with an empty gap in the middle. The grid still has to be one connected net, so the middle column (yellow) lies in the gap. Those 5 neurons win no sample (0 hits in the grid panel), 6 neurons in all. Their weights sit between the bands because neighbours on both sides pull on them. A large weight distance between grid neighbours marks a cluster border; drawn for every pair, that is the U-matrix, the usual way to read clusters off a trained SOM.

SOM, K-Means and neural networks

SOMK-MeansPerceptron / MLP
labelsnonenoneneeded
who learns per sampleBMU and its grid neighboursone centroid (batch mean)every weight, from the error
outputan ordered grid of prototypesK unordered centroidsa class or a value

The SOM's "neurons" are prototypes, not the weighted-sum units of a perceptron or a neural network: there is no activation function and no backpropagation. Its grid is a way to look at data in a low-dimensional picture, like PCA and t-SNE, but the result is a set of prototypes on a grid instead of one position per point. To judge plain clusters with real data points as centres, see K-Medoids and the silhouette.

See also Hopfield Network, another unsupervised network, which stores whole pictures in its weights with the Hebbian rule and recalls them from noise.

What the page leaves out

The data here is 2-D, so the grid can be drawn over it. Real SOMs map 10 to 1000 features onto the grid, and the grid (often hexagonal, often 10 × 10 or bigger) is then drawn alone, coloured by U-matrix distances or by one feature per picture. The page uses a square grid, a Gaussian neighbourhood with linear decay, and online updates; the batch SOM, other decay schedules, initializing along the first two principal components, growing SOMs and the U-matrix picture itself are only described.

On the mind map

Open the Machine Learning mind mapMachine LearningLearning setup: what feedback, how to scoreLearning setupLinear models: weighted sum w·x + bLinear modelsOther classic models: trees, margins, neighboursOther classic modelsUnsupervised: find structure without labelsUnsupervisedTraining: loss, gradient, small stepTrainingNeural networks: layers of σ(W·a + b)Neural networksArchitectures: how layers share informationArchitecturesLanguage models: predict the next tokenLanguage modelsLLM speed and tuning: cheaper to run, safer to useLLM speed and tuningRetrieval and agents: give the model data and toolsRetrieval and agentsK-meansK-meansassign to nearest centroid, move centroidSelf-Organizing MapWinner and grid neighbours move toward xK-Medoids and SilhouetteK-Medoids and SilhouetteReal points as centres; pick k by avg sApriori RulesApriori RulesSubset not frequent → skip the supersetFP-GrowthFP-GrowthTwo scans, a prefix tree, no candidatesDBSCANDBSCANgrow clusters from dense core pointsPCA vs t-SNEPCA vs t-SNEPCA keeps variance, t-SNE keeps neighboursk-means vs GMMk-means vs GMMhard circles vs soft covariance ellipsesEM algorithmEM algorithmE: soft labels, M: refit; ℓ never dropsHierarchical clusteringHierarchical clusteringMerge closest pair; cut the dendrogramMatrix factorization recsMatrix factorization recsRatings ≈ user vectors · item vectorsCollaborative FilteringCollaborative FilteringSimilar users' ratings fill the empty cellOpen the Machine Learning mind mapMachine Learningfind structure without labelsUnsupervisedK-meansK-meansassign to nearest centroid, move centroidSelf-Organizing MapWinner and grid neighbours move toward xK-Medoids and SilhouetteK-Medoids and SilhouetteReal points as centres; pick k by avg sApriori RulesApriori RulesSubset not frequent → skip the supersetFP-GrowthFP-GrowthTwo scans, a prefix tree, no candidatesDBSCANDBSCANgrow clusters from dense core pointsPCA vs t-SNEPCA vs t-SNEPCA keeps variance, t-SNE keeps neighboursk-means vs GMMk-means vs GMMhard circles vs soft covariance ellipsesEM algorithmEM algorithmE: soft labels, M: refit; ℓ never dropsHierarchical clusteringHierarchical clusteringMerge closest pair; cut the dendrogramMatrix factorization recsMatrix factorization recsRatings ≈ user vectors · item vectorsCollaborative FilteringCollaborative FilteringSimilar users' ratings fill the empty cell
This page on the Machine Learning mind map · 88 pages in 10 branches · open it to see the whole map and test yourself in recall mode.