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.

Feedforward

We can now write the activation of each neuron as follows,

Where

Backpropagation

The MSE cost function remains the same

(1)

Let’s apply Gradient Descent for the weight and bias of the last layer,

The chain rule now becomes,

(2)

Isolating each terms, we have

Similarly for the bias,

(3)

where

(4)

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**.

(5)

The only extra term we need to calculate is

(6)

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

(7)

Chain rule for the weight in the first layer

(8)

where

Gradient descent for the bias in the first layer

(9)

Chain rule for the bias in the first layer

(10)

where

(11)

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*).