https://github.com/michelin/torchsom
TorchSOM is a PyTorch-based library for training Self-Organizing Maps (SOMs), a type of unsupervised learning algorithm used for clustering and dimensionality reduction. Designed for scalability and ease of use, this implementation is optimized for large-scale data.
https://github.com/michelin/torchsom
clustering clustering-algorithm data-visualisation dimensionality-reduction-algorithms dimensionality-reduction-technique just-in-time just-in-time-learning pytorch pytorch-implementation self-organizing-maps unsupervised-machine-learning
Last synced: about 1 month ago
JSON representation
TorchSOM is a PyTorch-based library for training Self-Organizing Maps (SOMs), a type of unsupervised learning algorithm used for clustering and dimensionality reduction. Designed for scalability and ease of use, this implementation is optimized for large-scale data.
- Host: GitHub
- URL: https://github.com/michelin/torchsom
- Owner: michelin
- License: apache-2.0
- Created: 2025-02-27T13:01:52.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-09-01T14:37:18.000Z (about 1 month ago)
- Last Synced: 2025-09-01T15:28:43.835Z (about 1 month ago)
- Topics: clustering, clustering-algorithm, data-visualisation, dimensionality-reduction-algorithms, dimensionality-reduction-technique, just-in-time, just-in-time-learning, pytorch, pytorch-implementation, self-organizing-maps, unsupervised-machine-learning
- Language: Python
- Homepage: https://opensource.michelin.io/TorchSOM/
- Size: 134 MB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Citation: CITATION.cff
Awesome Lists containing this project
README
# `torchsom`: The Reference PyTorch Library for Self-Organizing Maps
[](https://pypi.org/project/torchsom/)
[](https://pypi.org/project/torchsom/)
[](https://pytorch.org/)
[](https://opensource.org/license/apache-2-0)[](https://sonarcloud.io/summary/new_code?id=michelin_TorchSOM)
[](https://sonarcloud.io/summary/new_code?id=michelin_TorchSOM)
[](https://sonarcloud.io/summary/new_code?id=michelin_TorchSOM)
[](https://sonarcloud.io/summary/new_code?id=michelin_TorchSOM)
[](https://sonarcloud.io/summary/new_code?id=michelin_TorchSOM)[](https://github.com/michelin/TorchSOM/actions/workflows/test.yml)
[](https://github.com/michelin/TorchSOM/actions/workflows/code-quality.yml)
[](https://pepy.tech/project/torchsom)
[](https://github.com/michelin/TorchSOM)[](https://github.com/psf/black)
[](https://pycqa.github.io/isort/)
[](https://github.com/astral-sh/ruff)
![]()
**A modern, comprehensive and GPU-accelerated PyTorch implementation of Self-Organizing Maps for scalable ML workflows**
[π Documentation](https://opensource.michelin.io/TorchSOM/)
| [π Quick Start](#-quick-start)
| [π Examples](notebooks/)
| [π€ Contributing](CONTRIBUTING.md)**β If you find [`torchsom`](https://github.com/michelin/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](assets/torchsom_jmlr.pdf). If you use `torchsom` in academic or industrial work, please cite both the paper and the software (see [`CITATION`](CITATION.cff)).
> **Note**: See the comparison table below to understand how `torchsom` differs from other SOM libraries, and explore our [Visualization Gallery](#-visualization-gallery) for example outputs.
## β‘ Why `torchsom`?
Unlike legacy implementations, `torchsom` is engineered from the ground up for modern ML workflows:
| | [torchsom](https://github.com/michelin/TorchSOM) | [MiniSom](https://github.com/JustGlowing/minisom) | [SimpSOM](https://github.com/fcomitani/simpsom) | [SOMPY](https://github.com/sevamoo/SOMPY) | [somoclu](https://github.com/peterwittek/somoclu) | [som-pbc](https://github.com/alexarnimueller/som) |
|---|---|---|---|---|---|---|
| **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**: `torchsom` supports **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](#-quick-start)
- [Tutorials](#-tutorials)
- [Installation](#-installation)
- [Documentation](#-documentation)
- [Citation](#-citation)
- [Contributing](#-contributing)
- [Acknowledgments](#-acknowledgments)
- [License](#-license)
- [Related Work and References](#-related-work-and-references)---
## π Quick Start
Get started with `torchsom` in just a few lines of code:
```python
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`](notebooks/iris.ipynb): Multiclass classification
- π· [`wine.ipynb`](notebooks/wine.ipynb): Multiclass classification
- π [`boston_housing.ipynb`](notebooks/boston_housing.ipynb): Regression
- β‘ [`energy_efficiency.ipynb`](notebooks/energy_efficiency.ipynb): Multi-output regression
- π― [`clustering.ipynb`](notebooks/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
```bash
pip install torchsom
```### π§ Development Version
```bash
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](https://opensource.michelin.io/TorchSOM/)
---
## π Citation
If you use `torchsom` in your academic, research or industrial work, please cite both the paper and software:
```bibtex
@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](CITATION.cff) file.
---
## π€ Contributing
We welcome contributions from the community! See our [Contributing Guide](CONTRIBUTING.md) and [Code of Conduct](CODE_OF_CONDUCT.md) for details.
- **GitHub Issues**: [Report bugs or request features](https://github.com/michelin/TorchSOM/issues)
---
## π Acknowledgments
- [Centre de MathΓ©matiques AppliquΓ©es (CMAP)](https://cmap.ip-paris.fr/) at Γcole Polytechnique
- [Manufacture FranΓ§aise des Pneumatiques Michelin](https://www.michelin.com/) for collaboration
- [Giuseppe Vettigli](https://github.com/JustGlowing) for [MiniSom](https://github.com/JustGlowing/minisom) inspiration
- The [PyTorch](https://pytorch.org/) team for the amazing framework
- Logo created using [DALL-E](https://openai.com/index/dall-e-3/)---
## π License
`torchsom` is licensed under the [Apache License 2.0](LICENSE). See the [LICENSE](LICENSE) file for details.
---
## π Related Work and References
### π Foundational Literature Papers
- Kohonen, T. (2001). [Self-Organizing Maps](https://link.springer.com/book/10.1007/978-3-642-56927-2). Springer.
### π Related Softwares
- [MiniSom](https://github.com/JustGlowing/minisom): Minimalistic Python SOM
- [SimpSOM](https://github.com/fcomitani/simpsom):Simple Self-Organizing Maps
- [SOMPY](https://github.com/sevamoo/SOMPY): Python SOM library
- [somoclu](https://github.com/peterwittek/somoclu): Massively Parallel Self-Organizing Maps
- [som-pbc](https://github.com/alexarnimueller/som): A simple self-organizing map implementation in Python with periodic boundary conditions
- [SOM Toolbox](http://www.cis.hut.fi/projects/somtoolbox/): MATLAB implementation---