Following up from the previous article, we now want to add a hidden layer of neurons between the output and the input layer.
The layer number is shown into brackets in superscript and the neuron number in each layer is shown in subscript.
We can now write the activation of each neuron as follows,
The MSE cost function remains the same
Let’s apply Gradient Descent for the weight and bias of the last layer,
The chain rule now becomes,
Isolating each terms, we have
Similarly for the bias,
The novelty is that we also need to calculate the sensitivity of the cost function with respect to the activation of the previous layer . That’s why we call this method Backpropagation.
The only extra term we need to calculate is
We can now look at adjusting the weight and bias of the first layer by using the same idea.
Gradient descent for the weight in the first layer
Chain rule for the weight in the first layer
Gradient descent for the bias in the first layer
Chain rule for the bias in the first layer
We now have all the bits and pieces to update the weights and biases of all the layers. We won’t look at the implementation into Python code just yet because this example is a bit meaningless in practice since there is only one input neuron i.e. one feature. (So the best classification we can get in this case is input = output).
In the next article, we will look at implementing a single-layer neural network with 3 input neurons (also known as Perceptron).