Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.A flexible net pulled onto the data
Picture a fishing net of nodes laid over your data. Each node has a position in data space. Show the net one data point at a time:
- The node closest to it (the best-matching unit) moves toward the point.
- Its neighbours on the net also move, but less.
Early on, whole regions of the net move together; later, only nearby nodes adjust. The net ends up draped over the data so that neighbours on the net hold similar data: a 2-D map of something high-dimensional.
SOMs turn high-dimensional data, such as 40-channel telemetry, spectra or engine health indicators, into a 2-D map engineers can read. Regions are operating modes, and a trajectory across the map shows a system drifting toward a fault. They have been used for condition monitoring, process supervision and exploratory analysis for decades.
- 1. The best-matching unit is…
- 2. Besides the BMU, which nodes move?
- 3. A trained SOM places similar data…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.One update by hand
BMU. For x = (1, 0) and nodes (0, 0), (1, 1), (0.9, 0.1), the squared distances are 1, 1 and 0.02, so the BMU is the third node.
Neighbourhood. h = exp(−g²/(2σ²)), where g is the grid distance from the BMU. With σ = 1:
- at the BMU itself, h = 1;
- one step away, h = e^(−0.5) = 0.607;
- two steps away, h = e^(−2) = 0.135.
Update. wᵢ ← wᵢ + η·hᵢ·(x − wᵢ). Take nodes at 0 and 2, sample x = 4, h = (1, 0.5), η = 0.5. The nodes move to 0 + 0.5·1·4 = 2 and 2 + 0.5·0.5·2 = 2.5.
Schedules. Exponential decay v(t) = v₀(v₁/v₀)^(t/T). For σ going from 4 to 0.25 over 100 steps, halfway (t = 50) gives σ = 4·(1/16)^0.5 = 1.
Quality measures.
- Quantization error: the mean distance from each sample to its BMU.
- Topographic error: the fraction of samples whose best and second-best nodes are not grid neighbours.
The steps in plain English:
- Lay out a grid of nodes (for example 10 × 10) and initialise their weights (random samples, or along the first two principal components).
- For each step: pick a sample, find its BMU, and move every node toward the sample by η·h, where h depends on its grid distance to the BMU.
- Shrink η and the neighbourhood width σ over time: first organise globally, then fine-tune locally.
- Evaluate quantization and topographic error, and visualise (component planes, U-matrix, hit counts).
- 1. Neighbourhood value two grid steps away with σ = 2?
- 2. Node at 1, sample 3, h = 1, η = 0.25: new weight?
- 3. Topographic error counts samples whose best two nodes are…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.What the schedule controls
Two phases. With a wide σ, updates move large areas of the grid together, so the map unfolds and orders itself globally. As σ shrinks, nodes specialise to local regions and quantize better.
- If σ shrinks too fast, the map can freeze with a fold or twist (a topological defect).
- If σ stays wide, the map stays smooth but blurry.
Exercise 1, an 8 × 8 SOM on the unit square: the topographic error fell from 0.826 (random initial nodes) to 0.006. Grid neighbours ended 0.111 apart in input space, against 0.476 for an average pair of nodes, so the map was well ordered.
The trade-off (exercise 2). For a 10 × 10 map on random colours:
- σ_end = 0.1 gave the lowest quantization error (0.111) but a patchy map (topographic error 0.256);
- σ_end = 3 gave a smooth map (0.023) but blurred prototypes (0.277).
Relation to k-means. As σ → 0, only the BMU moves, and online SOM becomes online k-means (MacQueen). A SOM is therefore k-means with a smoothness constraint across the grid. It quantizes somewhat worse than k-means with the same number of centres (0.095 for k-means in exercise 2), in exchange for the map.
Batch SOM. Instead of online updates, set each node to the neighbourhood-weighted mean of all samples, using BMUs from the previous step. It is deterministic, faster in vectorised code, and has no learning rate.
Visualisation.
- The U-matrix shows the distance between neighbouring nodes; high ridges mark cluster boundaries.
- Component planes colour the map by one input variable at a time.
- Hit maps count samples per node.
# pip install minisom
from minisom import MiniSom
som = MiniSom(10, 10, input_len=X.shape[1], sigma=3.0, learning_rate=0.5, random_seed=0)
som.pca_weights_init(X); som.train(X, 6000)
som.quantization_error(X), som.topographic_error(X), som.distance_map() # U-matrix- 1. As σ → 0, online SOM becomes…
- 2. The U-matrix shows…
- 3. Shrinking σ too fast risks…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
No global objective (online version). Kohonen’s online algorithm with a continuous data distribution is not gradient descent on any energy function in general (Erwin, Obermayer and Schulten, 1992). Convergence proofs exist only in special cases, such as 1-D maps. A modified BMU rule (Heskes, 1999) gives an energy function, the neighbourhood-weighted distortion, that batch SOM decreases.
Magnification. In the 1-D case the SOM’s node density follows p(x)^(2/3) (Ritter and Schulten, 1986). A faithful density estimate would follow p(x), and the mean-squared-error-optimal quantizer follows p(x)^(1/3). So a SOM’s node density is neither a density estimate nor an optimal quantizer; it sits between the two.
Dimension mismatch. A 2-D grid cannot preserve the topology of intrinsically higher-dimensional data. Folds and discontinuities are unavoidable, and the topographic error measures them.
Interview questions.
- SOM, k-means or t-SNE/UMAP for exploration? SOM gives a fixed, reusable map that new data can be projected onto (good for monitoring). t-SNE and UMAP give better local neighbourhood preservation for one-off visualisation. k-Means gives the best quantization but no map.
- How do you size and train a SOM? Use about 5√n nodes (a common heuristic), a grid aspect ratio following the two leading principal components, PCA initialisation, a wide initial σ shrinking to about 1, and check the topographic error.
- 1. The online SOM generally…
- 2. A common size heuristic for SOM nodes is about…
- 3. An advantage of SOM over t-SNE for monitoring is…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.Accuracy or smoothness?
History.
- T. Kohonen introduced self-organizing feature maps (1982), inspired by topographic maps in the cortex.
- C. von der Malsburg (1973) and D. Willshaw (1976) proposed earlier biologically motivated models.
- K. Kiviluoto (1996) defined the topographic error.
- J. Vesanto and colleagues developed the SOM Toolbox and the U-matrix-based visualisation practice.
Exercise 2. A 10 × 10 SOM on 1500 random RGB colours, 6000 steps, σ decaying from 5 to σ_end, 2 runs.
| σ_end | quantization error | topographic error |
|---|---|---|
| 0.1 | 0.111 | 0.256 |
| 0.5 | 0.134 | 0.116 |
| 1.0 | 0.157 | 0.076 |
| 2.0 | 0.212 | 0.047 |
| 3.0 | 0.277 | 0.023 |
| k-means, 100 centres | 0.095 | (no map) |
- A clean, monotone trade-off. Narrow final neighbourhoods fit prototypes tightly but tear the map; wide ones keep it smooth but blur the prototypes.
- σ_end ≈ 0.5–1 is a common compromise.
- k-means quantized best of all. The SOM’s extra error is the price of the map.
SOMs in AI, robotics and aerospace
- Condition monitoring: map engine or bearing health indicators and watch a unit’s trajectory move toward fault regions.
- Process and mission supervision: operators read a 2-D map of the operating state.
- Exploring high-dimensional sensor data such as spectra or vibration signatures before modelling.
References
- T. Kohonen (1982). “Self-organized formation of topologically correct feature maps.” Biological Cybernetics 43.
- T. Kohonen (2001). Self-Organizing Maps, 3rd ed. Springer.
- K. Kiviluoto (1996). “Topology preservation in self-organizing maps.” Proc. IEEE ICNN.
- E. Erwin, K. Obermayer, K. Schulten (1992). “Self-organizing maps: ordering, convergence properties and energy functions.” Biological Cybernetics 67.
- J. Vesanto, E. Alhoniemi (2000). “Clustering of the self-organizing map.” IEEE Transactions on Neural Networks 11(3).