U-matrix
self-organizing maps
machine learning
data visualization
unsupervised learning

U-matrix and self organizing maps

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Self-organizing maps (SOMs) are an unsupervised neural network technique devised by Teuvo Kohonen in the 1980s. This method is known for its ability to reduce high-dimensional data into lower dimensions — typically two for visual representation — while preserving the original data's topological relationships. SOMs are popularly used in exploratory data analysis, visualization, and clustering. One of the core components in the interpretation of self-organizing maps is the U-matrix, which offers insight into the clustering structure within the data.

Self-Organizing Maps

Basic Principles

A self-organizing map consists of a grid of neurons, each associated with a weight vector of the same dimension as the input data. During training, SOMs use a competitive learning process that involves the following steps:

  1. Initialization: Initialize the weight vectors of the neurons, often with small random values or using data samples.
  2. Sampling: A sample vector is randomly chosen from the input space.
  3. Best Matching Unit (BMU) Identification: Determine which neuron in the SOM has the weight vector closest to the sample input vector. This is done using a distance measure, usually the Euclidean distance.
    BMU=argminixwi\text{BMU} = \arg\min_i \| \mathbf{x} - \mathbf{w}_i \|
    Where x\mathbf{x} is the input vector and wi\mathbf{w}_i is the weight vector of the ii-th neuron.
  4. Updating: Update the weights of the BMU and its neighboring neurons to become more similar to the input sample, using the learning rate and neighborhood function.
    wi(t+1)=wi(t)+α(t)hci(t)(xwi(t))\mathbf{w}_i(t+1) = \mathbf{w}_i(t) + \alpha(t) \cdot h_{ci}(t) \cdot (\mathbf{x} - \mathbf{w}_i(t))
    α(t)\alpha(t) is the learning rate, which decreases over time. • hci(t)h_{ci}(t) is the neighborhood function, which decreases with the distance from the BMU.
  5. Iteration: Repeat the process for a fixed number of iterations or until convergence.

Key Characteristics

Topology Preservation: The neurons are arranged so that close neurons in the map are also close in the input space. • Dimensionality Reduction: Converts complex, high-dimensional data to easy-to-visualize low-dimensional maps.

U-Matrix

Definition

The unified distance matrix, or U-matrix, is a visualization technique used to represent the SOM grid's structure. It provides a clear understanding of the data's clustering by displaying the distance between the neurons. A U-matrix assigns a value to each neuron which reflects the average distance between its weight vector and those of its immediate neighbors.

Interpretation

Low Values: Indicate areas of the map where the neurons are similar, suggesting a dense cluster of data points. • High Values: Indicate larger distances between neighboring neurons, suggesting a potential cluster boundary.

The U-matrix is often visualized using a color gradient, where different colors represent varying distances, thus enhancing the identification of clusters and transitions between them.

Example

Suppose we have a dataset of three-dimensional points and a 10x10 SOM grid. After training the SOM, we calculate the U-matrix. Neurons representing similar data will have low U-matrix values, appearing in similar colors, while boundaries between clusters will have higher values and distinct colors.

Neuron CoordinateAverage Distance to NeighborsU-Matrix Value
(1, 1)0.2low
(5, 5)1.5medium
(9, 9)3.4high

The table above represents hypothetical U-matrix values, indicating that neurons at the boundary between clusters (e.g., (9, 9)) have higher U-matrix values.

Applications

SOMs and U-matrices find applications across a variety of fields:

Data Mining: Identifying patterns and anomalies in large datasets. • Bioinformatics: Cluster analysis of gene expression data. • Market Segmentation: Analyzing consumer behavior and grouping customers based on buying patterns.

Conclusion

Self-organizing maps and U-matrices provide powerful tools for data visualization and analysis, capturing complex data relationships and uncovering underlying structure. Through the use of SOMs and U-matrices, researchers and analysts can gain insights that are difficult to obtain through direct analysis of high-dimensional data. These methods excel in their ability to simplify the complex and illuminate hidden patterns embedded in vast datasets.


Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.