torchsom: The Reference PyTorch Library for Self-Organizing Maps
Project description
torchsom: The Reference PyTorch Library for Self-Organizing Maps
A modern, comprehensive and GPU-accelerated PyTorch implementation of Self-Organizing Maps for scalable ML workflows
๐ Documentation | ๐ Quick Start | ๐ Examples | ๐ค Contributing
โญ If you find torchsom valuable, please consider starring this repository โญ
๐ฏ Overview
Self-Organizing Maps (SOMs) remain highly relevant in modern machine learning (ML) due to their interpretability, topology preservation, and computational efficiency. They excel and are widely used in domains such as energy systems, biology, internet of things (IoT), environmental science, and industrial applications.
Despite their utility, the SOM ecosystem is fragmented. Existing implementations are often outdated, unmaintained, and lack GPU acceleration or modern deep learning (DL) framework integration, limiting adoption and scalability.
torchsom addresses these gaps as a reference PyTorch library for SOMs. It provides:
- GPU-accelerated training
- Advanced clustering capabilities
- A scikit-learn-style API for ease of use
- Rich visualization tools
- Robust software engineering practices
torchsom enables researchers and practitioners to integrate SOMs seamlessly into workflows, from exploratory data analysis to advanced model architectures.
This library accompanies the paper: torchsom: The Reference PyTorch Library for Self-Organizing Maps. If you use torchsom in academic or industrial work, please cite both the paper and the software (see CITATION).
Note: See the comparison table below to understand how
torchsomdiffers from other SOM libraries, and explore our Visualization Gallery for example outputs.
โก Why torchsom?
Unlike legacy implementations, torchsom is engineered from the ground up for modern ML workflows:
| torchsom | MiniSom | SimpSOM | SOMPY | somoclu | som-pbc | |
|---|---|---|---|---|---|---|
| Architecture Section | ||||||
| Framework | PyTorch | NumPy | NumPy | NumPy | C++/CUDA | NumPy |
| GPU Acceleration | โ CUDA | โ | โ CuPy/CUML | โ | โ CUDA | โ |
| API Design | scikit-learn | Custom | Custom | MATLAB | Custom | custom |
| Development Quality Section | ||||||
| Maintenance | โ Active | โ Active | โ ๏ธ Minimal | โ ๏ธ Minimal | โ ๏ธ Minimal | โ |
| Documentation | โ Rich | โ | โ ๏ธ Basic | โ | โ ๏ธ Basic | โ ๏ธ Basic |
| Test Coverage | โ ~86% | โ | ๐ ~53% | โ | โ ๏ธ Minimal | โ |
| PyPI Distribution | โ | โ | โ | โ | โ | โ |
| Functionality Section | ||||||
| Visualization | โ Advanced | โ | ๐ Moderate | ๐ Moderate | โ ๏ธ Basic | โ ๏ธ Basic |
| Clustering | โ Advanced | โ | โ | โ | โ | โ |
| JITL support | โ Built-in | โ | โ | โ | โ | โ |
| SOM Variants | ๐ง In development | โ | ๐ PBC | โ | ๐ PBC | ๐ PBC |
| Extensibility | โ High | ๐ Moderate | โ ๏ธ Low | โ ๏ธ Low | โ ๏ธ Low | โ ๏ธ Low |
Note:
torchsomsupports Just-In-Time Learning (JITL). Given an online query, JITL collects relevant datapoints to form a local buffer (selected first by topology, then by distance). A lightweight local model is then trained on this buffer, enabling efficient supervised learning (regression or classification).
๐ Table of Contents
- Quick Start
- Tutorials
- Installation
- Documentation
- Citation
- Contributing
- Acknowledgments
- License
- Related Work and References
๐ Quick Start
Get started with torchsom in just a few lines of code:
import torch
from torchsom.core import SOM
from torchsom.visualization import SOMVisualizer
# Create a 10x10 map for 3D input
som = SOM(x=10, y=10, num_features=3, epochs=50)
# Train SOM for 50 epochs on 1000 samples
X = torch.randn(1000, 3)
som.initialize_weights(data=X, mode="pca")
QE, TE = som.fit(data=X)
# Visualize results
visualizer = SOMVisualizer(som=som, config=None)
visualizer.plot_training_errors(quantization_errors=QE, topographic_errors=TE, save_path=None)
visualizer.plot_hit_map(data=X, batch_size=256, save_path=None)
visualizer.plot_distance_map(
save_path=None,
distance_metric=som.distance_fn_name,
neighborhood_order=som.neighborhood_order,
scaling="sum"
)
๐ Tutorials
Explore our comprehensive collection of Jupyter notebooks:
- ๐
iris.ipynb: Multiclass classification - ๐ท
wine.ipynb: Multiclass classification - ๐
boston_housing.ipynb: Regression - โก
energy_efficiency.ipynb: Multi-output regression - ๐ฏ
clustering.ipynb: SOM-based clustering analysis
๐จ Visualization Gallery
|
๐บ๏ธ D-Matrix Visualization Michelin production line (regression) |
๐ Hit Map Visualization Michelin production line (regression) |
๐ Mean Map Visualization Michelin production line (regression) |
||
|
๐บ๏ธ Component Planes Visualization Another Michelin line (regression)
|
๐ท๏ธ Classification Map Wine dataset (multi-classification) |
|||
|
๐ Cluster Metrics Clustering analysis |
๐ K-Means Elbow Optimal cluster selection |
๐ฏ HDBSCAN Cluster Map Cluster visualization |
||
๐พ Installation
๐ฆ PyPI
pip install torchsom
๐ง Development Version
git clone https://github.com/michelin/TorchSOM.git
cd TorchSOM
python3.9 -m venv .torchsom_env
source .torchsom_env/bin/activate
pip install -e ".[all]"
๐ Documentation
Comprehensive documentation is available at opensource.michelin.io/TorchSOM
๐ Citation
If you use torchsom in your academic, research or industrial work, please cite both the paper and software:
@inproceedings{Berthier2025TorchSOM,
title={torchsom: The Reference PyTorch Library for Self-Organizing Maps},
author={Berthier, Louis},
booktitle={Conference Name},
year={2025}
}
@software{Berthier_TorchSOM_The_Reference_2025,
author={Berthier, Louis},
title={torchsom: The Reference PyTorch Library for Self-Organizing Maps},
url={https://github.com/michelin/TorchSOM},
version={1.0.0},
year={2025}
}
For more details, please refer to the CITATION file.
๐ค Contributing
We welcome contributions from the community! See our Contributing Guide and Code of Conduct for details.
- GitHub Issues: Report bugs or request features
๐ Acknowledgments
- Centre de Mathรฉmatiques Appliquรฉes (CMAP) at รcole Polytechnique
- Manufacture Franรงaise des Pneumatiques Michelin for collaboration
- Giuseppe Vettigli for MiniSom inspiration
- The PyTorch team for the amazing framework
- Logo created using DALL-E
๐ License
torchsom is licensed under the Apache License 2.0. See the LICENSE file for details.
๐ Related Work and References
๐ Foundational Literature Papers
- Kohonen, T. (2001). Self-Organizing Maps. Springer.
๐ Related Softwares
- MiniSom: Minimalistic Python SOM
- SimpSOM:Simple Self-Organizing Maps
- SOMPY: Python SOM library
- somoclu: Massively Parallel Self-Organizing Maps
- som-pbc: A simple self-organizing map implementation in Python with periodic boundary conditions
- SOM Toolbox: MATLAB implementation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torchsom-1.1.1.tar.gz.
File metadata
- Download URL: torchsom-1.1.1.tar.gz
- Upload date:
- Size: 56.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2aa021f8b8e615f5869d2266d64f1fba7ef8e7a4acde76e3576c4da7c1bae1e2
|
|
| MD5 |
93859caf2f30eafeb2fc440a3d012ce2
|
|
| BLAKE2b-256 |
5a54ffa54acde666cd2033bf2aef91d274ea96b863e6ce2f81655c11dc464dff
|
File details
Details for the file torchsom-1.1.1-py3-none-any.whl.
File metadata
- Download URL: torchsom-1.1.1-py3-none-any.whl
- Upload date:
- Size: 58.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b640671ebc114193bed418729ef5243a70c55b6627100ae3c1ce48cd4e59d1d
|
|
| MD5 |
88c9f33df41094995900f6c0b20e5872
|
|
| BLAKE2b-256 |
c8223b863869e9109ca4da2dc078355bdd4ee8c96f959d84a9ff44d49ae704ae
|