SelfOrganizingMap<T>

Models & Types · AiDotNet.NeuralNetworks

Represents a Self-Organizing Map (Kohonen map): an unsupervised neural network that maps high-dimensional input onto a 2-D grid of prototype neurons, preserving input topology.

Inheritance: NeuralNetworkBase<T> → DeclaredModelLayoutBase<T> → VectorModelLayoutBase<T> → SelfOrganizingMap<T>

For Beginners

a SOM arranges data on a map so similar inputs land on nearby cells. Each cell remembers a prototype pattern; over training, cells specialise and neighbouring cells stay similar, which is great for visualising, clustering, and reducing high-dimensional data.

How It Works

The map stores one prototype (weight) vector per neuron. Prediction finds the Best Matching Unit (BMU) — the neuron whose prototype is closest to the input — and returns a one-hot activation. Training moves the BMU and its grid neighbours toward the input (competitive learning, Kohonen 1982).

Implementation note: the codebook is a single Tensor of shape [numNeurons, inputDimension] and all hot-path math (BMU distances, neighbourhood updates) runs through Engine tensor operations rather than scalar loops.

Reference: Kohonen, T. (1982). Self-organized formation of topologically correct feature maps. Biological Cybernetics, 43, 59–69.

Example

var arch = new NeuralNetworkArchitecture<float>(
    InputType.OneDimensional, NeuralNetworkTaskType.Clustering, inputSize: 10, outputSize: 100);
            
var trainX = Tensor<float>.CreateRandom(8, 10);
var trainY = Tensor<float>.CreateRandom(8, 100);
            
var result = new AiModelBuilder<float, Tensor<float>, Tensor<float>>()
    .ConfigureModel(new SelfOrganizingMap<float>(arch))
    .Build(trainX, trainY);
            
var output = result.Predict(Tensor<float>.CreateDefault(new[] { 1, 10 }, 0f));

Constructors

Constructor Summary
SelfOrganizingMap() Initializes a new instance with default architecture settings.
SelfOrganizingMap(NeuralNetworkArchitecture<T> architecture, ILossFunction<T> lossFunction, SelfOrganizingMapNNOptions options) Creates a Self-Organizing Map for the given architecture.

Properties

Property Summary
bool SupportsTraining { get; }

Methods

Method Summary
Dictionary<string, Tensor<T>> GetNamedLayerActivations(Tensor<T> input)
ModelMetadata<T> GetModelMetadata()