kohonen.kohonen.Map

class kohonen.kohonen.Map(params)[source]

Basic implementation of a rectangular N-dimensional self-organizing map.

A Self-Organizing or Kohonen Map (henceforth just Map) is a group of lightweight processing units called neurons, which are here implemented as vectors of real numbers. Neurons in a Map are arranged in a specific topology, so that a given neuron is connected to a small, specific subset of the overall neurons in the Map. In addition, the Map uses a distance metric (e.g., Euclidean distance) for computing similarity between neurons and cue vectors, as described below.

The Map accepts cues—vectors of real numbers—as inputs. In standard Map usage, cues represent some data point of interest. Normally applications of Maps use input vectors like the activation patterns for an array of sensors, term frequency vectors for a document, etc. Cues are stored in the Map as follows: First, a “winner” neuron w is chosen from the Map, and, second, the neurons in the Map topologically near w are altered so that they become closer to the cue. Each of these steps is described briefly below.

For the first step, the Map computes the distance between the cue and each of the Map neurons using its metric. The neuron closest to the cue under this metric is declared the “winner” w. Alternatively, the winner can be selected probabilistically based on the overall distance landscape.

Next, the Map alters the neurons in the neighborhood of w, normally using some function of the difference between the cue and the neuron being modified. The weight of the alteration decreases exponentially as the topological distance from w increases. The learning rule for a neuron n is

n += eta * exp(-d**2 / sigma**2) * (c - n)

where eta is the learning rate, sigma is called the neighborhood size, d is the topological distance between n and w, and c is the cue vector being stored in the map. Eta and sigma normally decrease in value over time, to take advantage of the empirical machine learning benefits of simulated annealing.

The storage mechanism in a Map has the effect of grouping cues with similar characteristics into similar areas of the Map. Because the winner—and its neighborhood—are altered to look more like the cues that they capture, the winner for a given cue will tend to win similar inputs in the future. This tends to cluster similar Map inputs, and can lead to interesting data organization patterns.

Attributes

shape

Methods

distance_heatmap(cue[, axes, lower, upper]) Return an image representation of the distance to a cue.
distances(cue) Get the distance of each neuron in the Map to a particular cue.
flat_to_coords(i) Given a flattened index, convert it to a coordinate tuple.
learn(cue[, weights, distances]) Add a new cue vector to the Map, moving neurons as needed.
neuron(coords) Get the current state of a specific neuron.
neuron_heatmap([axes, lower, upper]) Return an image representation of this Map.
reset([f]) Reset the neurons and timeseries in the Map.
sample(n) Get a sample of n neuron coordinates from the map.
smallest(distances) Get the index of the smallest element in the given distances array.
weights(distances) Get an array of learning weights to use for storing a cue.
winner(cue) Get the coordinates of the most similar neuron to the given cue.
__init__(params)[source]

Initialize this Map.

Methods

__init__(params) Initialize this Map.
distance_heatmap(cue[, axes, lower, upper]) Return an image representation of the distance to a cue.
distances(cue) Get the distance of each neuron in the Map to a particular cue.
flat_to_coords(i) Given a flattened index, convert it to a coordinate tuple.
learn(cue[, weights, distances]) Add a new cue vector to the Map, moving neurons as needed.
neuron(coords) Get the current state of a specific neuron.
neuron_heatmap([axes, lower, upper]) Return an image representation of this Map.
reset([f]) Reset the neurons and timeseries in the Map.
sample(n) Get a sample of n neuron coordinates from the map.
smallest(distances) Get the index of the smallest element in the given distances array.
weights(distances) Get an array of learning weights to use for storing a cue.
winner(cue) Get the coordinates of the most similar neuron to the given cue.

Attributes

shape
distance_heatmap(cue, axes=(0, 1), lower=None, upper=None)[source]

Return an image representation of the distance to a cue.

distances(cue)[source]

Get the distance of each neuron in the Map to a particular cue.

flat_to_coords(i)[source]

Given a flattened index, convert it to a coordinate tuple.

learn(cue, weights=None, distances=None)[source]

Add a new cue vector to the Map, moving neurons as needed.

neuron(coords)[source]

Get the current state of a specific neuron.

neuron_heatmap(axes=(0, 1), lower=None, upper=None)[source]

Return an image representation of this Map.

reset(f=None)[source]

Reset the neurons and timeseries in the Map.

f: A callable that takes a neuron coordinate and returns a value for
that neuron. Defaults to random values from the standard normal.
sample(n)[source]

Get a sample of n neuron coordinates from the map.

The returned values will be flat indices; use flat_to_coords to convert them to neuron indices.

smallest(distances)[source]

Get the index of the smallest element in the given distances array.

Returns a flat index; use flat_to_coords to convert this to a neuron index.

weights(distances)[source]

Get an array of learning weights to use for storing a cue.

winner(cue)[source]

Get the coordinates of the most similar neuron to the given cue.

Returns a flat index; use flat_to_coords to convert this to a neuron index.

Related Topics

This Page