Unsupervised Neural Networks

Self Organizing Maps

A Self Organizing Map, or SOM, is a neural network that learns to arrange high-dimensional data onto a low-dimensional grid. Similar inputs activate nearby neurons, creating a visual map of hidden structure in the data.

What is a SOM?

A SOM is trained without labels. Every neuron owns a weight vector. For each input, the closest neuron wins. Then the winner and its neighbors move closer to that input. Over many iterations, the grid becomes an organized map of the input space.

Competitive learning
🎯

Best Matching Unit

The neuron whose weight vector is closest to the current input is called the BMU.

🌊

Neighborhood

Nearby neurons also update, which keeps the map smooth and topologically ordered.

📉

Learning Rate

The learning rate controls how strongly neurons move toward each training sample.

🧭

Dimensionality Reduction

Complex input patterns become easier to inspect on a 2D neuron grid.

Algorithm

The core idea is simple: find the winning neuron, then pull it and its neighbors toward the input.

Initialize neurons. Each neuron receives a random weight vector with the same dimension as the input data.
Choose one training sample. The sample may represent a color, a point, a customer profile, an image feature vector, or any numeric vector.
Find the BMU. Compute the distance between the sample and every neuron. The closest neuron wins.
Update the neighborhood. Move the winner and nearby neurons toward the input. The update strength decreases with grid distance.
Repeat. Gradually reduce the learning rate and neighborhood radius until the map stabilizes.

Example 1: Color Clustering SOM

In this example, each input is an RGB vector: [red, green, blue]. The SOM learns to arrange colors so that similar colors appear near each other.

Input dimension: 3

How this example works

The grid starts with random colors. During training, random colors are sampled from a curated palette. The closest neuron becomes the winner, and surrounding neurons shift toward the sampled color.

After training, nearby cells tend to form smooth color regions: blues near cyans, reds near pinks, yellows near greens, and so on.

0 Iterations
0.50 Learning rate
9.00 Radius
💡 Notice how SOM does not need labels such as “red” or “blue”. It discovers similarity using numeric distance.

Example 2: 2D Cluster Mapping SOM

In this example, each input is a 2D point: [x, y]. The SOM learns to bend its grid over the shape of the data distribution.

Input dimension: 2

How this example works

The data contains three visible clusters. The SOM starts as a loose grid of random neurons. During training, the neurons are pulled toward dense areas of data while preserving neighborhood structure.

The result is a flexible 2D map that approximates the topology of the dataset. This is useful for exploratory clustering, anomaly detection, customer segmentation, and visualization.

0 Iterations
0.35 Learning rate
6.00 Radius
✔️ The lines between neurons show the SOM topology. The map learns the dataset while staying connected.

Example 3: User-Defined 3D Numerical SOM

This example uses 9 editable samples. Each sample has 3 dimensions: [x₁, x₂, x₃]. A 3 × 3 SOM also has 9 neurons with random 3D weight vectors. The 2D plot shows dimensions x₁ and x₂, while x₃ is represented by color intensity.

9 samples · 3 dimensions · 9 neurons

Editable 3D samples

Change any sample value between 0 and 1. Select an active sample, then train one step to see the exact SOM math update.

Sample x₁ x₂ x₃
0 Iterations
BMU
Best distance
💡 The active vector is compared with all 9 neuron weight vectors. The closest neuron becomes the BMU. Then the BMU and nearby neurons move toward the selected input vector.

2D SOM plot

SOM neurons Samples BMU Active sample

Projection: horizontal axis = x₁, vertical axis = x₂. Color intensity represents x₃.

Distance table

For each neuron, we calculate the Euclidean distance between the active input vector and the neuron's current 3D weight vector.

d(x, Wᵢ) = √((x₁ - wᵢ₁)² + (x₂ - wᵢ₂)² + (x₃ - wᵢ₃)²)
Neuron Weight [w₁,w₂,w₃] Grid Distance

Active math update

This panel shows the latest training step. The BMU gets the strongest update. Neighbors get smaller updates based on grid distance.

W(t + 1) = W(t) + α × h × (x - W(t))
x
α
h exp(-gridDistance² / (2r²))
r
Press “Train active sample” to see the numerical SOM update.