# Backpropagation simply explained

During my studies, I attended a few classes in which the backpropagation algorithm was explained. Unfortunately it was not very clear, notations and vocabulary were messy and confusing. As a result, many students ended up saying it is a complicated algorithm. In fact, it is pretty simple and this is all the more surprising when you know that it now fuels so many real-world applications. This article simply aims to explain backpropagation as simply as it should be with the minimum one requires to understand it.

Let’s consider a multi-layer perceptron modelled by a function , where denotes all the parameters of the network (weights and biases). Training this network consists in learning from a training dataset a set of parameters such that the resulting network has the desired behaviour. The training dataset is composed of pairs , where for each , is the known desired output of input . The performance of the network is evaluated with an error/cost function defined as

where is the loss function such that measures the discrepancy between the desired output $\vec{y}^{(i)}$ and the actual output computed by the neural network . Common loss functions are the square error (for regression) or the negative log-likelihood (for classification). The training is then cast into the minimisation of , which is usually carried out by a variant of the **gradient descent algorithm**. Let’s consider the three layers displayed in the following figure.

The output of neuron of layer is given by

where is the activation function of the neurons.

The vanilla gradient descent algorithm specifies that the update rule of the weight connecting the neuron of layer and the neuron of layer is given by

where is a scalar parameter called the learning rate. So far we have just spoken of gradient descent and it is only now that we introduce the term of **backpropagation** of the gradient, which is simply an algorithm to compute the gradient . It is based on the chain rule, the univariate and the multivariate versions.

where is known as the error of neuron $j$ of layer and is computed by applying the multivariate chain rule:

Therefore, by computing at layer , we can compute at the previous layer $l$. Starting from the output layer, the process is repeated until the input layer is reached. This iterative update to compute the gradient of $E$ with respect to all the weights is known as the backpropagation algorithm. Since is non convex (except when there is no hidden layer), gradient descent will likely fall into a local minimum. The important question is to find a suitable local minimum, where the resulting network generalize well to new examples.

Note that the gradient descent algorithm refers to an optimisation algorithm to minimize a differentiable function while the backpropagation algorithm is the procedure to compute the gradient of the error with respect to any weights of a neural network. However, abusively, it is common to refer to the whole process (gradient descent + backpropagation) as backpropagation.

### Matrix form

When implementing backpropagation, it is important to write the computations in a matrix form so that efficient matrix multiplication algorithms can be used. and are row vectors, is a matrix. We then have:

with

and