SelfOrganizingMap1D

class trackstream.preprocess.SelfOrganizingMap1D(nlattice: int, nfeature: int, sigma: float = 0.1, learning_rate: float = 0.3, decay_function: Union[Callable, Literal['asymptotic']] = 'asymptotic', random_seed: Optional[int] = None, **kwargs)[source]

Bases: object

Initializes a Self-Organizing Map, (modified from [MiniSom]).

Parameters
nlatticeint

Number of lattice points in the 1D SOM.

nfeatureint

Number of the elements of the vectors in input.

sigmafloat, optional (default=1.0)

Spread of the neighborhood function, needs to be adequate to the dimensions of the map. (at the iteration t we have sigma(t) = sigma / (1 + t/T) where T is #num_iteration/2)

learning_rateinitial learning rate

(at the iteration t we have learning_rate(t) = learning_rate / (1 + t/T) where T is #num_iteration/2)

decay_functionfunction (default=None)

Function that reduces learning_rate and sigma at each iteration the default function is:

learning_rate / (1+t/(max_iterarations/2))

A custom decay function will need to to take in input three parameters in the following order:

  1. learning rate

  2. current iteration

  3. maximum number of iterations allowed

random_seedint, optional (default=None)

Random seed to use.

Notes

neighborhood_function‘gaussian’

Function that weights the neighborhood of a position in the map.

activation_distance‘euclidean’

Distance used to activate the map.

References

MiniSom

Giuseppe Vettigli. MiniSom: minimalistic and NumPy-based implementation of the Self Organizing Map.

frankenz

Josh Speagle. Frankenz: a photometric redshift monstrosity.

Attributes Summary

decay_function

Decay function.

learning_rate

Learning Rate.

nfeature

Number of features.

nlattice

Number of lattice points.

sigma

Methods Summary

binned_weights_init(data[, byphi])

Initialize prototype vectors from binned data.

neighborhood(c, sigma)

Returns a Gaussian centered in c.

pca_weights_init(data, **kw)

Initializes the weights to span the first two principal components.

quantization(data)

Assigns a code book (weights vector of the winning neuron) to each sample in data.

quantization_error(data)

Returns the quantization error computed as the average distance between each input sample and its best matching unit.

train(data, num_iteration[, random_order, ...])

Trains the SOM.

update(x, win, t, max_iteration)

Updates the weights of the neurons.

winner(x)

Computes the coordinates of the winning neuron for the sample x.

Attributes Documentation

decay_function

Decay function.

learning_rate

Learning Rate.

nfeature

Number of features.

nlattice

Number of lattice points.

sigma

Methods Documentation

binned_weights_init(data, byphi=False, **kw)[source]

Initialize prototype vectors from binned data.

neighborhood(c, sigma) numpy.ndarray[source]

Returns a Gaussian centered in c.

pca_weights_init(data, **kw)[source]

Initializes the weights to span the first two principal components.

This initialization doesn’t depend on random processes and makes the training process converge faster.

It is strongly recommended to normalize the data before initializing the weights and use the same normalization for the training data.

quantization(data)[source]

Assigns a code book (weights vector of the winning neuron) to each sample in data.

quantization_error(data)[source]

Returns the quantization error computed as the average distance between each input sample and its best matching unit.

train(data, num_iteration: int, random_order=False, progress: bool = False, **kw) None[source]

Trains the SOM.

Parameters
datandarray or list

Data matrix.

num_iterationint

Maximum number of iterations (one iteration per sample).

random_orderbool (default=False)

If True, samples are picked in random order. Otherwise the samples are picked sequentially.

verbosebool (default=False)

If True the status of the training will be printed at each iteration.

update(x, win, t, max_iteration)[source]

Updates the weights of the neurons.

Parameters
xnp.array

Current pattern to learn.

wintuple

Position of the winning neuron for x (array or tuple).

tint

Iteration index

max_iterationint

Maximum number of training itarations.

winner(x)[source]

Computes the coordinates of the winning neuron for the sample x.