A neural network needs to be trained to solve a prediction problem. The training (or learning) is a process of finding the weight and bias values that will produce the desired output at the output layer when a certain input is given to the network. How does a neural network learn? For a human to learn to do things, we will be told that we are doing it right or wrong. For example, if we are to learn to play football, we watch how the ball flies as we kick the ball. The next time we kick the ball, we remember the mistake that we have done before and improvise the movement to kick the ball a bit better. Similarly, a neural network learns to solve a problem by comparing the output that is produced by the network with the output that was meant to produce. The difference between the network’s output and the true output is the amount of error that the network needs to reduce to improve its output. This is formulated as follows.
is a measure of how badly the network is performing. Specifically, it quantifies the error between the true outputs and the predicted outputs. The measure is known as the cost function, is a function that needs to be minimized in order for the network to learn to produce the correct output. is the true output, is the predicted output produced by the network and is the total number of training examples.
The above cost function is for regression problem. For binary classification problem, the cost functions is given as follows.
For multi-class classification, the cost function is given as follows.
Minimizing the cost function involves adjusting the weights of the connections between two neurons in the network. The weights are adjusted in such a way that the output that will be produced by the network is closed to the actual output. This involve propagating the error from the output layer to the the hidden layer(s) and the input layer. Hence the process is called backpropagation. The commonly used backpropagation algorithm is the Gradient Descent.
Gradient Descent is an optimization (iterative) algorithm for finding the parameters (weights) that will minimize the cost function. It works by calculating the partial derivatives with respect to each weight (gradient) of the cost function and use the calculated gradient to update the weights. The weight update is defined as follow.
where is the step size or learning rate and is the gradient.
The learning rate defines how much a step is taken or how much the weights are updated. A small learning rate causes small changes to the weights. Hence, the Gradient Descent can be slow or in another words it would take a longer time to converge. In contrast, a large learning rate causes large update and results in a faster convergence rate. However, it may cause the Gradient Descent to miss the minima (overshoot) and fail to converge.
The gradient is calculated using the chain rule. Using the network shown in Figure 1 as an example, the calculation of the gradient is given as follows.