SOM — CPU Implementation

The SOM class is the core NumPy-based Self-Organizing Map. All public symbols are importable directly from NNSOM:

from NNSOM.som import SOM

som = SOM((8, 8))
som.init_w(data)
som.train(data, init_neighborhood=3, epochs=200, steps=100)
class NNSOM.som.SOM(dimensions)[source]

Bases: object

A class to represent a Self-Organizing Map (SOM), a type of artificial neural network trained using unsupervised learning to produce a two-dimensional, discretized representation of the input space of the training samples.

dimensions

The dimensions of the SOM grid. Determines the layout and number of neurons in the map.

Type:

tuple, list, or array-like

numNeurons

The total number of neurons in the SOM, calculated as the product of the dimensions.

Type:

int

pos

The positions of the neurons in the SOM grid.

Type:

array-like

neuron_dist

The distances between neurons in the SOM.

Type:

array-like

w

The weight matrix of the SOM, representing the feature vectors of the neurons.

Type:

array-like

sim_flag

A flag indicating whether the SOM has been simulated or not.

Type:

bool

__init__(self, dimensions):

Initializes the SOM with the specified dimensions.

init_w(self, x):

Initializes the weights of the SOM using principal components analysis on the input data x.

sim_som(self, x):

Simulates the SOM with x as the input, determining which neurons are activated by the input vectors.

train(self, x, init_neighborhood=3, epochs=200, steps=100):

Trains the SOM using the batch SOM algorithm on the input data x.

quantization_error(self, dist)[source]

Calculate quantization error

topological_error(self, data)[source]

Calculate 1st and 1st-2nd toplogical error

distortion_error(self, data)[source]

Calculate distortion error

save_pickle(self, filename, path, data_format='pkl'):

Saves the SOM object to a file using the pickle format.

load_pickle(self, filename, path, data_format='pkl'):

Loads a SOM object from a file using the pickle format.

Initialization and training

SOM.init_w

Initializes the weights of the SOM using principal components analysis (PCA) on the input data x.

SOM.train

Trains the SOM using the batch SOM algorithm on the input data x.

SOM.sim_som

Simulates the SOM with x as the input, determining which neurons are activated by the input vectors.

Clustering

SOM.cluster_data

Cluster the input data based on the trained SOM reference vectors.

Quality metrics

SOM.quantization_error

Calculate quantization error

SOM.topological_error

Calculate topological error

SOM.distortion_error

Calculate distortion

Persistence

SOM.save_pickle

Save the SOM object to a file using pickle.

SOM.load_pickle

Load the SOM object from a file using pickle.