Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TorchSOM is a PyTorch-based library for training Self-Organizing Maps (SOMs), a model trained in an unsupervised manner, that can be used for clustering, dimensionality reduction and data visualization. It is designed to be scalable and user-friendly.

License

Notifications You must be signed in to change notification settings

michelin/TorchSOM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

torchsom: The Reference PyTorch Library for Self-Organizing Maps

PyPI version Python versions PyTorch versions License: Apache 2.0

Quality Gate Status Reliability Rating Security Rating Maintainability Rating Coverage

Tests Code Quality Downloads GitHub stars

Code style: black Imports: isort Ruff

TorchSOM_logo

A modern, comprehensive and GPU-accelerated PyTorch implementation of Self-Organizing Maps for scalable ML workflows

πŸ“„ Paper | πŸ“š 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 torchsom differs 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 βœ… 90% ❌ 🟠 ~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 can then be trained on this buffer, enabling efficient supervised learning (regression or classification).


πŸ“‘ Table of Contents


πŸš€ 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:

🎨 Visualization Gallery

πŸ—ΊοΈ D-Matrix Visualization

Michelin production line (regression)

U-Matrix
πŸ“ Hit Map Visualization

Michelin production line (regression)

Hit Map
πŸ“Š Mean Map Visualization

Michelin production line (regression)

Mean Map
πŸ—ΊοΈ Component Planes Visualization

Another Michelin line (regression)

Component Plane 1 Component Plane 2
🏷️ Classification Map

Wine dataset (multi-classification)

Classification Map
πŸ“Š Cluster Metrics

Clustering analysis

Cluster Metrics
πŸ“ˆ K-Means Elbow

Optimal cluster selection

K-Means Elbow
🎯 HDBSCAN Cluster Map

Cluster visualization

HDBSCAN Cluster Map


πŸ’Ύ 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:

@misc{berthier2025torchsom,
    title={torchsom: The Reference PyTorch Library for Self-Organizing Maps},
    author = {Berthier, Louis and Shokry, Ahmed and Moreaud, Maxime and Ramelet, Guillaume and Moulines, Eric},
    year={2025},
    eprint={2510.11147},
    archivePrefix={arXiv},
    primaryClass={stat.ML},
    note={Preprint submitted to Journal of Machine Learning Research},
    url={https://arxiv.org/abs/2510.11147}
}

@software{berthier2025torchsom_software,
    author={Berthier, Louis},
    title={torchsom: The Reference PyTorch Library for Self-Organizing Maps},
    year={2025},
    version={1.1.1},
    url={https://github.com/michelin/TorchSOM},
    note = {Documentation available at \url{https://opensource.michelin.io/TorchSOM/}}
}

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.


πŸ™ Acknowledgments


πŸ“„ License

torchsom is licensed under the Apache License 2.0. See the LICENSE file for details.


πŸ“š Related Work and References

πŸ“– Foundational Literature Papers

πŸ”— 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

About

TorchSOM is a PyTorch-based library for training Self-Organizing Maps (SOMs), a model trained in an unsupervised manner, that can be used for clustering, dimensionality reduction and data visualization. It is designed to be scalable and user-friendly.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published