LearnBack(Var InputValues: Array; Var outputValues: Array);
LearnBack(Var InputValues: System.Array; Var outputValues: System.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. To execute the example, add links to the NN, IO system assemblies.
Function m_BPTrain(Net: NeuralNetwork): NeuralNetwork;
Var
epoch, sampleNumber, i: Integer;
NumberOfOut, NumberOfInp: Integer;
inputs, outputs: Array Of Double;
NetFile: File;
TextW: ITextWriter;
Begin
NetFile := New File.Create;
TextW := NetFile.OpenTextWriter("C:/BPTrain.txt", True);
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);
// learn the 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;
// verify whether network has been learned
If Net.DeltasMinimumReachedBP(0.0001) Then
Return Net;
End If
End For;
End For;
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 file C:/BPTrain.txt.
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.
Imports System.IO;
Imports Prognoz.Platform.Interop.NN;
…
Public Shared Function m_BPTrain(Net: NeuralNetwork): NeuralNetwork;
Var
epoch, sampleNumber, i: Integer;
NumberOfOut, NumberOfInp: Integer;
inputs, outputs: System.Array;
NetFile: StreamWriter;
Begin
NetFile := File.CreateText("C:/BPTrain.txt");
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 entry 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);
// learn the network
Net.LearnBack(Var inputs, Var outputs);
NetFile.WriteLine("Epoch of learning : '" + epoch.ToString() + "'");
NetFile.WriteLine(" maximum delta value: " + net.GetMaximumWeightDelta().ToString());
NetFile.WriteLine(" output data: ");
outputs := Net.GetOutputValues();
For i := 0 To NumberOfOut - 1 Do
NetFile.WriteLine(" " + outputs[i].ToString());
End For;
// verify whether network has been learned
If Net.DeltasMinimumReachedBP(0.0001) Then
NetFile.Close();
Return Net;
End If
End For;
End For;
NetFile.Close();
Return Net;
End Function;
After executing the example the network is learned according to the assigned parameters. Changing output data and delta value are written to the file C:/BPTrain.txt.
See also: