Gradient descent is widely used and is one of the best optimization algorithms.
It is a technique use to find the minimum value of a function.
This function could be anything. In the context of a neural network, the function we are interested in is called the cost function. It is the difference between the predicted and the real value.
Remember the objective of training a neural network is to find the optimal values of the parameters that minimize the cost function
One important point to note however is that we do not have a complete view of the cost function. If that was the case, it would be easy to spot the minima and the corresponding values of the parameters at said minima. What we have is a particular instantiation of the cost function for specific values of the network’s parameters.
Using this instantiation as our starting point, we compute the gradient of the cost with respect to all the parameters and then update the parameters of the model. Because the gradient of a function gives us the direction of steepest ascend, moving in the negative direction of gradient equates to descending down the slope. Also, the size of the steps or rate at which we descend down the slope is determine by a constant k called the learning rate. If this constant is too small, we take too long to converge to the minima, increasing the training time and computational cost. If the learning rate is too large, we might overshoot and miss the local minima.
In summary, if you have a function, gradient descent provides a way to iteratively update the parameters of a function to some optimal values where the function is lowest. This is done by computing the gradient of the function with respect to all the parameters of the function, updating the values of the parameters and measuring the change in the function
Why does the gradient descent work? To measure the change in a function, we appeal to the Taylor series
Assuming our cost function is a 2D function f(x, y)
For small changes in x and y, according to the Taylor series:
Change in Cost in vector:
The change in the cost in vector form is the gradient of the cost with respect to both parameters times the change in the parameters.
Since the change in parameters is equal to the negative of the gradient. Then the change in cost is minus the change in gradient squared
Change in parameters is equal to minus the learning rate times the gradient. For each iteration of the gradient descent, the new parameter values are calculated like this:
The learning rate theta tells us how fast how fast we descent down the slope.
You do this several times until you have the minimum of the cost function
Geometrically, gradient descent is like being on an uneven hilly landscape and taking steps towards the lowest point
We took an example of a 2D function with just two parameters but even if our function had millions of parameters like is the case with most neural networks, which have parameters in the millions and billions, the same logic still applies. We will need to compute the gradient of the cost with respect to every parameter to be able to update them. As computation increases with the dimensionality of the function, gradient is very compute expensive .

Leave a Reply