The gradient descent method can be a very useful tool to optimize multivariable functions. However, it has its issues, too. In this topic, you will touch on potential difficulties that might arise when working with this method, as well as ways to overcome them.
Stationary points
If we were to draw a straight line between any two points of a strictly convex function, this line would always be above the function for that interval. For example:
and , examples of strictly convex functions.
A stationary point is the one where all partial derivatives of a function are equal to zero. When the function is not strictly convex, the stationary point could be a local minimum or a saddle point.
and , examples of functions with saddle points.
A sequence generated by the gradient descent method converges on a stationary point for the objective function. It follows that the gradient method works best for strictly convex functions, as there is usually a single well-defined stationary point: its global minimum.
The method can become very inefficient — and even fail — for functions with regions that plateau. The gradient will be equal to the zero vector at these points, and this would mean that the sequence will get stuck for all subsequent iterations.
The gradient descent method depends on the starting point you choose. By starting the sequence at a different point, you are often able to avoid regions with stationary points and the issues that come with those. Furthermore, a good staring point can even improve convergence!
For example, let's consider the following function: will serve as a starting point. Then, by applying the gradient descent method, you will get this:
You can see in the animation how the method arrives at the wrong stationary point.
If instead you choose as a starting point and apply the method again, you will see the following picture:
This time, the method arrives at the right stationary point: the minimum!
Step size
As you've seen previously, the gradient descent method is also heavily dependent on the chosen step size. Sometimes an ill-chosen constant step size for a particular function can get the sequence stuck in a back-and-forth situation. In the example below, you can see how fairly inefficient zig-zag patterns occur as the direction of the gradient oscillates unchecked.
In addition, instead of getting stuck between two opposite points, you can see that the sequence grows farther and farther away from the minimum for a given step size. This means even though the gradient vector points in the direction of the steepest descent, following it doesn't guarantee descent!
Like any other vector, the search vector has both direction and magnitude.
Then, the apparently contradictory statement from above makes sense when you consider that the negative gradient vector points to the direction where the minimizer is, but it doesn't tell us how far away it is. By evaluating the gradient at each step, the vector is continuously adjusted to point in the correct direction. Then, you need a way to adjust its size to guarantee it is correctness as well.
Formally, the descent method should follow two conditions to avoid overshoots and slow convergence. These are the Wolfe conditions:
With .
The first condition is known as the Armijo rule. It breaks down as follows:
On the left-hand side of the inequality, you have the value that the objective function will take for the next step , expressed in terms of the current step :
On the right-hand side, you subtract a term proportional to the amount of change expected after a step in the direction of the steepest descent, from the value of the objective function at the current step:
Recall that the directional derivative gives us information of the rate at which the objective function would change if you were to follow the direction given by some vector.
By keeping , the right-hand side constrains the left-hand side to a maximum value that should only be a small proportion of the expected change. The Armijo rule guarantees that the next step will result in a significant decrease with respect to the current step. This secures that the descent method actually descends.
The second condition is known as the curvature condition. It constrains the expected change of the next iteration on the right-hand side of the inequality, to a proportion of the expected change for the current iteration on the left-hand side. It guarantees that each next step will be closer to the minimizer, as the expected rate of change decreases as you approach the minimum or a similar stationary point.
As an example, let's consider the following objective function:
with the following values:
for both constants from the Wolfe conditions, as well as the current step value.
You can compute the gradient at this point like this:
Then, you can compute the directional derivative at the current step:
Now, you can substitute these values for both Wolfe conditions, starting with the Armijo rule:
and following with the curvature condition:
The intersection of both intervals gives us the range of step values, for which significant descent is guaranteed, without any overshoots:
You can narrow this interval by choosing different values of and . Typically, and .
Choosing the best step size is an optimization problem on its own. It is your job to make sure that the step size optimization algorithm you pick fulfills both Wolfe conditions!
Laying the groundwork
As you've seen, the gradient descent method requires a step size optimization at every iteration. Usually, this represents an iterative process by itself, thus the method can become computationally costly and often slow to converge. However, it provides a solid foundation, from which more refined methods that can provide much faster convergence stem, like the conjugate gradient, or the Nesterov Accelerated Gradient descent algorithms.
Conclusion
- The gradient descent method is very sensitive to the choice of step size. A poor choice might lead to a slow convergence or no convergence at all.
- The gradient descent method depends heavily on the shape of the function. It works best on strictly convex functions, but it can also work on quasi-convex functions, as long as you avoid saddle points.
- By tweaking both the starting point and the step size optimization algorithm, you can achieve reasonably fast convergence.
- The step size optimization algorithm should fulfill both Wolfe conditions to avoid divergence and slow convergence.
- The method is the foundation for more advanced optimization algorithms.