Function SupervisedTrain(inputdata As Variant, outputdata As Variant) As Integer '0=unsuccessful and 1 = successful
Dim i, j, k As Integer
If UBound(inputdata) <> Network.Layers(1).NeuronCount Then 'Check if correct amount of input is given
SupervisedTrain = 0
Exit Function
End If
If UBound(outputdata) <> Network.Layers(Network.LayerCount).NeuronCount Then 'Check if correct amount of output is given
SupervisedTrain = 0
Exit Function
End If
Call Run(inputdata) 'Calculate values of all neurons and set the input
'Calculate delta's
For i = 1 To Network.Layers(Network.LayerCount).NeuronCount
DoEvents
'Deltas of Output layer
Network.Layers(Network.LayerCount).Neurons(i).Delta = Network.Layers(Network.LayerCount).Neurons(i).Value * (contd)
* (1 - Network.Layers(Network.LayerCount).Neurons(i).Value) * (contd)
* (outputdata(i) - Network.Layers(Network.LayerCount).Neurons(i).Value)
For j = Network.LayerCount - 1 To 2 Step -1
DoEvents
For k = 1 To Network.Layers(j).NeuronCount
DoEvents
Network.Layers(j).Neurons(k).Delta = Network.Layers(j).Neurons(k).Value * (contd)
* (1 - Network.Layers(j).Neurons(k).Value) * Network.Layers(j + 1).Neurons(i).Dendrites(k).Weight * (contd)
* Network.Layers(j + 1).Neurons(i).Delta 'Deltas of Hidden Layers
Next k
Next j
Next i
For i = Network.LayerCount To 2 Step -1
DoEvents
For j = 1 To Network.Layers(i).NeuronCount
DoEvents
Network.Layers(i).Neurons(j).Bias = Network.Layers(i).Neurons(j).Bias + (contd)
+ (Network.LearningRate * 1 * Network.Layers(i).Neurons(j).Delta) 'Calculate new bias
For k = 1 To Network.Layers(i).Neurons(j).DendriteCount
DoEvents
'Calculate new weights
Network.Layers(i).Neurons(j).Dendrites(k).Weight = Network.Layers(i).Neurons(j).Dendrites(k).Weight + (contd)
(Network.LearningRate * Network.Layers(i - 1).Neurons(k).Value * Network.Layers(i).Neurons(j).Delta)
Next k
Next j
Next i
SupervisedTrain = 1
End Function