Let’s break down the maths behing Neural Networks. There are two main processes going on when a NN tries to learn a decision boundary :

  • the feedforward process
  • the back-propagation

They apply respectively to move forward with the weights we learned in order to compute the outcome, and to move backwards to update the weights once the outcome (an therefore the error) has been computed. You guessed it, the hard part is the back-propagation.

image

The Chain Rule

No spoil, but we’ll need to compute a big derivatives at some point in the learning process. How can we efficiently break down big derivatives into smaller steps ? Using the chain rule, yes. The chain rule can be applied here to drastically decrease the numbers of gradients to compute and the complexity of the calculus.

What the chain rule states is that when composing functions, the derivatives multiply :

And in more complex cases :

Notation

“Notation in Deep Learning is important”, My Mom

We wiil first cover the basic 1 Hidden Layer Neural Net case before extending to Deep Neural Nets. We’ll introduce basic notations :

  • is the outcome of an input that went through a neuron
  • is to which we applied an activation function
  • is the error. It could be the cross-entropy or the Mean Squared Error for example.

Let’s represent visually the Neuron Net we are talking about, and where the derivatives apply :

image

The derivatives apply in the back-propagation. In the back propagation, we compute :

We will see in the back-propagation section how to break down this problem.

The Feedforward Process

The feedforward process is the process in Neural Networks that turns an input into an output. It describes the mathematical operations that allow to turn the input into an output. For example, on the example displayed above, with 2 hidden layers and 1 final layer :

Where :

The error function will remain the same when computing how far out predicted output is from the true output :

The cost function is the sum of the losses of over all training examples :

The Back-propagation

The second step of the process is to apply the Back-propagation. What this basically means is that we mapped our input to an output, and based on the performance of this mapping, we should be able to addjust the weights and bias in each layer accordingly.

We can compute the gradients with respect to each and every weight in the layers.

To update the gradient, we will do it individually :

Feed-forwarding is nothing more than composing some functions. Therefore, back-propagation is nothing more than applying the chain rule to split the gradients into multiplicative derivatives.

We can compute the derivative of the error function as :

Let’s break down the first derivative, since it’s the deepest dependency we have in our network so far :

image

Where is the value taken by the output of a neuron at each step.

image

For example, in the first step :

Notice how when computing the derivative with respect to one of the first weights of the network, you need the whole “chain” to be computed. And there is not only one way to reach neuron, since in deeper networks, we might go through other neurons. Therefore, by computing the partial derivatives, we will re-use them often.

We will need the derivative of the sigmoid function in the partial derivatives later on :

Using the expression of we just defined, we can compute the partial derivatives ! For simplicity, we’ll use the mean squared error as an error metric :

For the next derivative : , recall that . Therefore :

Finally, we need to compute . Recall that . Therefore :

We now have characterized all the steps of the learning process. For deeper neuronal nets, we’re just doing more of this steps, and making sure to re-use the gradients already computed accross layers.

Computing the partial derivatives is useless if we don’t update the weights using gradient descent :

Where is the learning rate. Progressively, we’ll be shifting in the right direction !

image

At this point, all that’s left is to re-apply the feedforward process with the updated weights, and so on, until you reach your maximum number of iterations or any other stopping criteria.


Like it? Buy me a coffeeLike it? Buy me a coffee

Leave a comment