HomeAI & Machine LearningNeural Gas

🧠 Neural Gas

Visualise unsupervised learning: Self-Organising Map (SOM/Kohonen) and Neural Gas adapt their nodes to match a data distribution. Watch the grid fold and unfold to cover the data manifold.

AI & Machine Learning3DModerate60 FPS
neural-gas ↗ Open standalone

About this simulation

This simulation trains two classic unsupervised competitive learning algorithms — the Self-Organising Map (SOM) and Neural Gas — live in your browser. A grid or set of nodes is pulled toward randomly sampled points from a chosen data distribution, gradually reshaping itself until its nodes cover the manifold the data actually lives on.

🔬 What it shows

Each training step draws a random point from the data distribution and updates every node by an amount that shrinks with distance from the "winning" node. In SOM, that distance is measured along the fixed 2D grid topology using a Gaussian neighbourhood function h = e^(−d²/2σ²), which is why the SOM canvas shows connected grid lines that bend and fold to match the data. In Neural Gas, nodes have no fixed topology — instead every node is ranked by distance to the input and updated by h = e^(−rank/λ), so the nodes drift freely to cover the distribution without a rigid grid.

🎮 How to use

Switch between the SOM and Neural Gas tabs, then pick a Data Distribution preset — Uniform Square, Ring, Two Gaussians or Half-Moon — to see how differently each algorithm adapts. Adjust Learning Rate η and Neighbourhood σ (both decay automatically as training progresses) or λ for Neural Gas, change the Grid Size for more or fewer nodes, and press Run to animate up to 200 epochs while the live Quantisation Error readout tracks how well the nodes fit the data.

💡 Did you know?

The Self-Organising Map was invented by Finnish researcher Teuvo Kohonen in 1982 as a model of how the brain's sensory cortex organises itself topographically, and it remains widely used today for visualising high-dimensional data in 2D. Neural Gas, introduced a decade later by Martinetz and Schulten, drops the fixed grid entirely and often converges to a lower quantisation error precisely because its nodes are free to reorganise their own effective topology to match the data.

Frequently asked questions

What is the difference between a Self-Organising Map and Neural Gas?

A Self-Organising Map arranges its nodes on a fixed grid (here a square grid up to 16×16) and updates neighbours based on their grid distance to the winning node, which forces the map to preserve the 2D grid topology even as it bends to fit the data. Neural Gas has no grid at all: every node is simply ranked by its distance to the current input point, and update strength falls off with rank rather than spatial position, letting the nodes settle into whatever arrangement best represents the data.

How does the SOM learning rule actually update the nodes?

For each sampled data point, the simulation first finds the "best matching unit" (BMU) — the grid node closest to that point — then updates every node i by Δwᵢ = η·h(d)·(x−wᵢ), where h(d) = e^(−d²/2σ²) and d is the grid distance from node i to the BMU. Nodes near the BMU move almost as much as the BMU itself, while distant nodes barely move, which is what lets the whole grid smoothly fold to trace the data manifold.

Why do the learning rate and neighbourhood radius shrink over time?

Both η and σ (or λ for Neural Gas) are multiplied by an exponential decay factor e^(−t·k) as training epochs progress toward the 200-epoch cap, so early updates are large and affect a wide neighbourhood (coarse, global organisation) while later updates are small and local (fine-tuning). Without this annealing schedule the map would either never stabilise or would fail to unfold correctly from its random initial state.

What does Quantisation Error measure and why does it matter?

Quantisation error is the average distance from a sample of data points to their nearest node, computed here over 100 points every 5 epochs; a lower value means the nodes sit closer to where the data actually is, so the map represents the distribution more accurately. Watching this number fall during training is a direct, numeric way to confirm the visual impression that the grid is converging onto the data.

Why does a Ring or Half-Moon distribution look harder for the SOM grid to fit than a Uniform Square?

A square grid's fixed neighbour connections naturally match a convex, filled region like the Uniform Square preset, but distributions such as the Ring or Half-Moon are curved and hollow, forcing the grid to twist, fold back on itself, or leave nodes stranded in empty space between the arms of the shape. Neural Gas, lacking a rigid topology, typically tracks these awkward shapes more cleanly since its nodes are not constrained to stay connected to fixed neighbours.

⚙ Under the hood

Watch a neural gas network adapt to data topology — competitive learning with neighbourhood ranking.

Neural GasUnsupervised LearningTopologyAI

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)