Skip to main content

SOMptimised

An optimised version of sklearn-som with extended features.

Additional features:

  • Can save additional features into the SOM beyond those used to train it
  • Can serialise (i.e. save SOM state into a binary file onto the disk)
  • Can load back the SOM in its previous state from a binary file on the disk

This SOM implementation has been optimised in terms of speed with respect to sklearn-som just by using more efficient numpy functions and features and by reducing the number of loops when possible.

Performance boost does not scale linearly with SOM or dataset size but, as an indication, a 50x50 SOM run on 14 000 data points (1 epoch) takes on my machine:

  • 7.3s of CPU and wall time to fit with this library
  • 2min of CPU and wall time to fit with sklearn-som

For more details, please visit the documentation.

How to use

Using the SOM is quite straightforward. To do so, data has to be load as a 2D array

import pandas

table      = pandas.read_csv('examples/iris_dataset/iris_dataset.csv')
target     = table['target']
table      = table[['petal length (cm)', 'petal width (cm)', 'sepal length (cm)']]
data       = table.to_numpy()

data_train = data[:-10] # Training set
data_test  = data[-10:] # Test set

Training is done with the fit method and predictions are done with the predict method

from   SOMptimised_dev import SOM, LinearLearningStrategy, ConstantRadiusStrategy, euclidianMetric

# Define SOM parameters
lr     = LinearLearningStrategy(lr=1)
sigma  = ConstantRadiusStrategy(sigma=0.8)
metric = euclidianMetric

nf     = data_train.shape[1] # Number of features
som    = SOM(m=1, n=3, dim=nf, lr=lr, sigma=sigma, metric=metric, max_iter=1e4, random_state=None)
som.fit(data_train, epochs=1, shuffle=True, n_jobs=1)

pred_test = som.predict(data_test)

The current state of the SOM can be saved into a binary file and loaded back from it into any python code using the write and read methods

som.write('output_file')

new_som = SOM.read('output_file')

License

MIT License

Copyright (c) 2022 Wilfried Mercier

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Metadata

Release files for SOMptimised 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for SOMptimised 1.1.0
File Size Uploaded
SOMptimised-1.1.0.tar.gz 18.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for SOMptimised 1.1.0
File Interpreter ABI Platform
SOMptimised-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 45.2 kB

Release files / SOMptimised-1.1.0.tar.gz

Download URL SOMptimised-1.1.0.tar.gz
Size 18.3 kB
Tags Source
SHA-256 checksum
How to use checksums
82df650c65e0cb394e8d8603458af2d739f00adaf797e9f7a24be8302d878383
BLAKE2b-256 checksum
How to use checksums
e790190ffd2d4e85524b5c2f19f181204e24d648cdc686f970331700736a3daf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.7

Release files / SOMptimised-1.1.0-py3-none-any.whl

Download URL SOMptimised-1.1.0-py3-none-any.whl
Size 26.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
05aeec2556673c0322b78413a7970a310aa5bbc343205e16e6972d7d7a98a2d8
BLAKE2b-256 checksum
How to use checksums
f1b20a391d7461c80c9025f355e2cf2692a57263d0c7f7f0c477524eb9babcfe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.7

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page