INeuralNetwork.GetClosestNeuron

Syntax

GetClosestNeuron: Integer;

Description

The GetClosestNeuron method returns index of the neuron, which weight vector being least of all different from the tested input vector.

Comments

GetClosestNeuron is used only for Kohonen self-organizing maps.

After creation and learning, a Kohonen self-organizing map can classify the input vector and determine its class. A class is the returned index of the neuron. The overall number of the classes equals to the number of the neurons in the output layer of the network and can be obtained by means of the INeuralNetwork.GetNumberOfOutputs method.

A Kohonen self-organizing map can be presented in a linear manner (all the neurons of the input layer form a single line) or in as a two-dimensional map (neurons of the input layer form a rectangle or a square). By default, the linear view is used, but it is possible to replace it by assigning the number of lines using the INeuralNetwork.SetRowWidth or INeuralNetwork.SetRowWidthEx method. For example, the first layer of the network consists of 20 neurons. If one should indicate the layer to contain four lines, the map shall be represented as a rectangle with the sides, which size is 4x5 neurons. Learning and work with the map is performed in accordance with the assigned logical structure. The current number of map lines can be obtained using the INeuralNetwork.GetRowWidth or INeuralNetwork.GetRowWidthEx method.

Usually, a Kohonen self-organizing map consists of one layer of neurons. This layer is simultaneously the input and the output layer. Networks with a large number of layers are unpredictable and unteachable.

The example of the GetClosestNeuron method use:

After this it is possible to classify the tested input vectors. Call INeuralNetwork.PropagateSOFM, then call GetClosestNeuron.

Example

As an example, the method is given, that has a Kohonen self-organizing map fed into its input (the Net parameter). To execute the example, add links to the NN, IO system assemblies.

Sub m_SetRowWidth(Net: NeuralNetwork);
Var
    epoch, i, NumberOfInp, j: Integer;
    OutputRes, InpData: Array Of Double;
    NetFile: File;
    TextW: ITextWriter;
Begin
    TextW := NetFile.OpenTextWriter("C:/LearnRes.txt"True);
    If Net.GetRowWidth = 1 Then
        Net.SetRowWidth(2);
    End If;
    Net.InitSynapsesConvex;
    For epoch := 1 To 100 Do
        Net.PropagateSOFM;
        Net.LearnSOFM;
        OutputRes := Net.GetOutputValues;
        TextW.WriteLnString("Epoch of learning '" +  epoch.ToString + "'.  Output  values:");
        For i := 0 To OutputRes.Length - 1 Do
            TextW.WriteLnString("  " + OutputRes[i].ToString);
        End For;
    End For;
    TextW.WriteLnString("Learning is completed");
    TextW.WriteLnString("------------------");
    TextW.WriteLnString("Classification");
    TextW.WriteLnString("Number of classes: " + Net.GetNumberOfOutputs.ToString);
    NumberOfInp := Net.GetNumberOfInputs;
    InpData := New Double[NumberOfInp];
    For i := 0 To 5 Do
        TextW.WriteLnString("Input vector '" + i.ToString + "': ");
        For j := 0 To NumberOfInp - 1 Do
            InpData[j] := i + j * 0.33;
            TextW.WriteLnString("  " + InpData[j].ToString);
        End For;
        Net.SetInputValuesConvex(InpData, 1);
        Net.PropagateSOFM;
        TextW.WriteLnString("   Class: " + Net.GetClosestNeuron.ToString);
    End For;
    Net.DeleteNetwork;
End Sub m_SetRowWidth;

After calling the method, the Kohonen self-organizing map is transformed into a grid (if it had a linear view). The Kohonen self-organizing map is also learned. The output data that is changed in the process of learning, is written to the file C:/LearnRes.txt. Then six vectors will be tested. Their data and class are written to the file C:/LearnRes.txt file. After classification of the vectors the map is destroyed.

See also:

INeuralNetwork