Skip to main content

A mix of jcfaracco/xpysom-dask and fcomitani/simpsom, with heavy modifications

Project description

XPySom-dask

Self Organizing Maps with Dask Support and pretty hexagonal plot.

Simpsom-Dask is a partial rewrite of XPySom-Dask with vizualisation elements introduced in Simpsom. Some optimizations have been added, and the vizualisation elements have been improved, mostly to fit my needs.

Installation

You can download XPySom-dask from PyPi:

pip install simpsom-dask

By default, dependencies for GPU execution are not downloaded.

You can also choose to clone this repo and then run

cd simpsom-dask
pip install -e .

if you would like to modify things on the fly.

How to use it

The module interface is similar to MiniSom. In the following only the basics of the usage are reported, for an overview of all the features, please refer to the original MiniSom examples you can refer to: https://github.com/JustGlowing/minisom/tree/master/examples (you can find the same examples also in this repository but they have not been updated yet).

In order to use Simpsom you need your data organized as a Numpy matrix where each row corresponds to an observation or as list of lists like the following:

chunks = (4, 2)
data = [[ 0.80,  0.55,  0.22,  0.03],
        [ 0.82,  0.50,  0.23,  0.03],
        [ 0.80,  0.54,  0.22,  0.03],
        [ 0.80,  0.53,  0.26,  0.03],
        [ 0.79,  0.56,  0.22,  0.03],
        [ 0.75,  0.60,  0.25,  0.03],
        [ 0.77,  0.59,  0.22,  0.03]]      

Then you can train XPySom just as follows:

from simsom_dask import Simpsom

import dask.array as da

from dask.distributed import Client, LocalCluster

client = Client(LocalCluster())

dask_data = da.from_array(data, chunks=chunks)

som = Simpsom(6, 6, 4, sigma=0.3, learning_rate=0.5, use_dask=True, chunks=chunks) # initialization of 6x6 SOM
som.train(dask_data, 100) # trains the SOM with 100 iterations

You can obtain the position of the winning neuron on the map for a given sample as follows:

som.winner(data[0])

Differences with MiniSom

  • The batch SOM algorithm is used (instead of the online used in MiniSom). Therefore, use only train to train the SOM, train_random and train_batch are not present.
  • decay_function input parameter is no longer a function but one of 'linear', 'exponential', 'asymptotic'. As a consequence of this change, sigmaN and learning_rateN have been added as input parameters to represent the values at the last iteration.
  • New input parameter std_coeff, used to calculate gaussian exponent denominator d = 2*std_coeff**2*sigma**2. Default value is 0.5 (as in Somoclu, which is different from MiniSom original value sqrt(pi)).
  • New input parameter xp (default = cupy module). Back-end to use for computations.
  • New input parameter n_parallel to set size of the mini-batch (how many input samples to elaborate at a time).
  • Hexagonal grid support is recommended.

Authors

Copyright (C) 2025 Hugo Banderier

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simpsom_dask-1.0.2.tar.gz (28.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simpsom_dask-1.0.2-py3-none-any.whl (55.4 kB view details)

Uploaded Python 3

File details

Details for the file simpsom_dask-1.0.2.tar.gz.

File metadata

  • Download URL: simpsom_dask-1.0.2.tar.gz
  • Upload date:
  • Size: 28.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for simpsom_dask-1.0.2.tar.gz
Algorithm Hash digest
SHA256 a988eed2537eb3ce8968ea07c4e4b28e701583ee074bd9bc18360e8b5247035c
MD5 dbcb264905462957854668e9eadfedac
BLAKE2b-256 e4b91c63b9a4bd1526490cb6e6a42bdae7fd3542301557e995769eb56a103ce1

See more details on using hashes here.

File details

Details for the file simpsom_dask-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: simpsom_dask-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 55.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for simpsom_dask-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 61a9b93e418f5701a96d664bbaef1689e290a28f26ec409a365c60a1b3f38f64
MD5 6d7abe8a3ecc099e8fc43046e37ed14e
BLAKE2b-256 d1fb5875bbcff4eecb978f1e5207bca63cc71d0fdb5976ce133b7b7c06a14a64

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page