algorithms.qsom.som.SOM¶
- class algorithms.qsom.som.SOM(dimx, dimy, unit_len, sigma=1.0, learning_rate=0.5, init='random')[source]¶
Bases:
object
- __init__(dimx, dimy, unit_len, sigma=1.0, learning_rate=0.5, init='random')[source]¶
Create a new Self-Organizing Map, with a rectangular shape.
- Parameters:
dimx – The X-dimension of the map.
dimy – The Y-dimension of the map.
unit_len – Size of the vector associated to each unit.
sigma – Size of the neighborhood.
learning_rate – Initial learning rate.
init – Method to initialize the neurons’ units (vectors). Either ‘random’ (uniform distribution in [0,1)), or zero (all values are set to 0s).
Methods
__init__
(dimx, dimy, unit_len[, sigma, ...])Create a new Self-Organizing Map, with a rectangular shape.
compute_winner_node
(data)Compute the Best Matching Unit to the input vector data.
get_unit
(idx)Return the weights of a neuron, identified by its index idx.
neighborhood
(center)Compute the neighborhood matrix for all nodes.
Return the mean error of the map.
update
(data, winner)Update the SOM towards a pattern to learn, given a winner node.
Attributes
learning_rate
sigma
- _compute_activation_map(data)[source]¶
Compute the matrix in which an element (i,j) is the response of the neuron with coordinates (i,j) to the vector data. The lower the activation, the closest the neuron is to data.
- _decay(value, step)[source]¶
Decay a value based on the time step.
To allow for long-term adaptation, we simply return the value without decaying.
- compute_winner_node(data)[source]¶
Compute the Best Matching Unit to the input vector data.
The Best Matching Unit is the closest neuron to data, i.e., the one with the lower activation (a bit misleading).
- Parameters:
data – The input vector, a NumPy array of same size as #input_len.
- Returns:
The closest neuron’s identifier (
- neighborhood(center)[source]¶
Compute the neighborhood matrix for all nodes.
- Parameters:
center – The index of the center neuron in this neighborhood.
- Returns:
A matrix in which an element, indexed by (i,j), is the distance of the neuron with coordinates (i,j) to the center neuron (weighted by the size of the neighborhood).
- update(data, winner)[source]¶
Update the SOM towards a pattern to learn, given a winner node.
Every node in the map is updated, based on the neighborhood function (relative distance to the winner node).
- Parameters:
data – The pattern to learn, i.e., a vector of weights (of same shape as #input_len).
winner – The index of the winner node, i.e., the closest node.