LearnBack(Var InputValues: Array; Var outputValues: Array);
InputValues. Real array of input values.
outputValues. Real array of point-of-reference output values.
The LearnBack method performs iteration on learning back-propagation network.
One iteration is called an epoch of learning. Short algorithm:
Output values are calculated using current values of synapse weights.
Calculated output values are compared to the point-of-reference output values. Value of the error is defined.
The value of the error is used to calculate the delta value, which is used to correct synapse weights. See INeuralNetwork.DeltasMinimumReachedBP and INeuralNetwork.GetMaximumWeightDelta.
Synapse weights are corrected.
Iterations continue the specified number of times or until the assigned accuracy of the network has been reached, that is, till delta is small enough.
As an example, a function is provided that learns the network. A back-propagation network is fed at the input of the function: the Net parameter.
Add links to the IO and NN system assemblies.
Function m_BPTrain(Net: NeuralNetwork): NeuralNetwork;
Var
epoch, sampleNumber, i: Integer;
NumberOfOut, NumberOfInp: Integer;
inputs, outputs: Array Of Double;
TextW: ITextWriter;
Begin
TextW := File.OpenTextWriter("C:\BPTrain.txt", True);
TextW.Encoding := CodePage.UTF8;
NumberOfOut := Net.GetNumberOfOutputs;
outputs := New Double[NumberOfOut];
NumberOfInp := Net.GetNumberOfInputs;
inputs := New Double[NumberOfInp];
For epoch := 1 To 3000 Do
For sampleNumber := 1 To NumberOfOut Do
// Set input values
For i := 0 To NumberOfInp - 1 Do
inputs[i] := 0.5;
End For;
// Set output values
For i := 0 To NumberOfOut - 1 Do
outputs[i] := 0.5;
End For;
// Set learning parameters
Net.SetNju(0.1);
Net.SetMju(0);
// Train network
Net.LearnBack(inputs, outputs);
TextW.WriteLnString("Epoch of learning: '" + epoch.ToString + "'");
TextW.WriteLnString(" maximum value delta: " + net.GetMaximumWeightDelta.ToString);
TextW.WriteLnString(" output data: ");
outputs := Net.GetOutputValues;
For i := 0 To NumberOfOut - 1 Do
TextW.WriteLnString(" " + outputs[i].ToString);
End For;
// Check if network learned
If Net.DeltasMinimumReachedBP(0.0001) Then
Return Net;
End If
End For;
End For;
TextW.Flush;
Return Net;
End Function m_BPTrain;
After executing the example the network is learned according to the assigned parameters. Changing output data and delta value are written to the C:/BPTrain.txt file.
See also: