We already learn how we can use newton method to minimize error iteratively here. In this post, we will discuss about how we can use gradient descent method to minimize error interatively. When we later talk about neural network (deep neural network will be deep learning), we can say that understanding gradient descent is half of understanding neural network. And in fact, gradient descent is really easy to understand, likewise neural network. It’s true and not exaggerated 😀

Let’s talk about how gradient descent works first. This is also used in other machine learning methods, such as in logistic regression for binary classification here. Let’s assume we have function shown picture below to be minimized.

Our goal is to find the value of that minimizes . In the picture above is the pink point. To achieve that point, we will use the gradient information, and we know that gradient actually represents the slope our our function. Then case is, when we have positive gradient, the curve will increase when increases. And when we have negative gradient, the curve will decrease when increases. Thus, how to update our value so that our decreases constantly? The answer is by subtracting our current with the gradient, specifically weighted gradient. In this case, weighting value will be how big step we want to make in every interation update. Mathematically, gradient descent is written as follow.

Let’s put an example for clearer understanding. In picture above, we assume that we have . We will demonstrate how we can reach pink point minimizing value, in this case the pink point will be . Let’s say we are now in . Here is how we update our in every iteration.

In only 5 iterations, we already get which is closed to the pink point we already know for this case, which is . We can just continue to iterate it, and it will be converged at in our case here. Easy, right?

In machine learning, our will be our error function/loss function. And by using this gradient descent method, we will try to minimize our error in every iteration update. Again, weighting value here is how big step we want in every iteration update. Bigger , faster to converge, and vice versa. But, bigger can be not stable and even cause not being able to converge.

Maybe some of you will ask, how we can know the gradient value of our loss function? In fact we often cannot know the mathematical form of our loss function, not like in the example we know that it is . How we can take first differential of it to get gradient? The answer is we will use discrete method when we will implement into a code in computer. In this case, our gradient will be . “New” here means the value in current iteration, and “old” means the value we get in the previous iteration.

That’s all. Easy but powerful, right?