Comprehensive Notes on First-Order Optimization and Gradient Descent
First-Order Condition and Differentiability
The primary advantage of zero-order optimization methods is their general applicability, but this generality acts as a limitation because they do not utilize specific function properties like continuity or differentiability. If a function is known to be differentiable, optimization can be made more efficient by leveraging the first derivative, or gradient. The first-order condition for optimality states that for a differentiable function , a point is a potential optimum if the gradient at that point is equal to the zero vector. This is expressed as:
In the one-dimensional case where , this condition simplifies to . Points that satisfy this condition are known as critical points or stationary points. However, the first-order condition is a necessary but not sufficient condition for optimality. While every local or global optimum must be a critical point, not every critical point is an optimum; critical points also encompass maxima, minima, inflection points (in one dimension), and saddle points. High-level examples include the function or , where derivatives can be analyzed to identify these stationary points.
Convexity and Global Optimality
Convexity is a property that makes the first-order condition sufficient for optimality. To understand this, several definitions are required. A point is a convex combination of two points and if it can be expressed as for . A set is considered a convex set if every pair of points within the set has its convex combination also within the set. Geometrically, this means the line segment joining any two points in the set is entirely contained within the set. A function is convex if its domain is a convex set and for any pair , the inequality holds for all . Strict convexity occurs when the inequality is strict for and .
A function is convex if and only if its linear approximation at any point is a global underestimator of the function. This is defined by the first-order condition for convexity: for all . This relationship implies that if the gradient at a point is zero (), then for all points in the set, making a global minimum. Consequently, for convex functions, any local minimum is a global minimum, and the first-order condition is both necessary and sufficient. This efficiency is why convex optimization is a dominant field. A function is concave if its negative is convex; maximizing a concave function is equivalent to minimizing a convex function.
The Gradient Descent Algorithm
Gradient descent is a local optimization method that utilizes the property that the gradient points in the direction of steepest ascent. Conversely, the negative gradient points in the direction of steepest descent. By consistently moving in the direction of the negative gradient, the algorithm is guaranteed to find a descent direction at each step. The algorithm requires an initial point , a step size parameter , and a maximum number of steps . For each step , the gradient is calculated at the previous point , and the update is performed: . The output includes the history of update steps and their corresponding function evaluations.
Matrix Differentiation Rules
Efficient computation of gradients in multi-dimensional space often employs matrix differentiation using the denominator layout convention. Key results include:
(i) If is a linear transformation, then .
(ii) For a scalar , and .
(iii) For a quadratic form , . If is symmetric, this simplifies to .
(iv) If where both are functions of a vector , then .
(v) For a scalar where is a function of vector , .
An example of a two-dimensional gradient descent involves minimizing , which has a gradient . With an initial point such as and , the algorithm quickly settles to the global minimum.
Numerical Differentiation and Step Size Sensitivity
When analytic gradients are too complex to compute, numerical differentiation provides an approximation. While forward and backward difference quotients have significant approximation errors, the central difference quotient is preferred as errors tend to cancel. It is defined as: . In multivariate contexts, the -th partial derivative is approximated using the -th standard basis vector :
A common choice for the small value is , where is machine epsilon ( in R). Modern machine learning primarily uses automatic differentiation rather than numerical differentiation to avoid rounding and truncation errors.
Sensitivity to the step size is critical. If is too small, convergence is excessively slow because movement is minuscule. If is too large, update steps may actually increase the function value, leading to divergence. Common strategies involve setting as a fixed value like (where is a negative integer) or using a diminishing step size like .
Limitations of Gradient Descent
Gradient descent faces two major practical issues involving the direction and magnitude of the negative gradient. First, "zigzag" behavior occurs because the gradient is always perpendicular to function contours. In objective functions with narrow valleys, the directions oscillate rapidly, requiring many steps to reach the minimum. This is observable in quadratic functions of the form , particularly when the matrix has disparate eigenvalues, creating narrow contours.
Second, "slow-crawling" behavior occurs near critical points. Since the gradient vanishes at stationary points (), the magnitude of the update steps shrinks as the algorithm approaches the optimum. Because step length is calculated as , vanilla gradient descent makes very little progress in flat regions of the function surface.
Variants of Gradient Descent
To address standard gradient descent's weaknesses, several variants exist:
First-Order Coordinate Descent: This method simplifies high-dimensional problems into a series of one-dimensional problems. Instead of updating all coordinates at once, the algorithm cycles through each coordinate , minimizing the function with respect to while holding other coordinates constant. The update is: , where includes the most recent updates for all preceding dimensions.
Momentum-Based Gradient Descent: Borrows from the physical intuition of a ball rolling down a bowl. Momentum allows the update to carry forward previous descent directions, reducing oscillations. The descent direction is an exponentially weighted moving average (EWMA) of negative gradients: , where is a decay rate. The update is .
Normalized Gradient Descent: Addresses the slow-crawling issue by normalizing the negative gradient, ensuring each step has a constant length . The update is: . In practice, a small constant (e.g., ) is added to the denominator as to prevent division by zero and maintain numerical stability.
Specialized Variants in Machine Learning
Machine learning leverages numerous advanced extensions of gradient descent. Stochastic Gradient Descent (SGD) reduces redundant calculations by processing subsets of data rather than the full batch. Nesterov Accelerated Gradient (NAG) provides a refined version of momentum. AdaGrad (Adaptive Gradient Algorithm) adapts the learning rate for each parameter based on historical gradients. Adam (Adaptive Moment Estimation) combines momentum with adaptive learning rates, while RMSprop (Root Mean Squared Propagation) improves upon AdaGrad to prevent the learning rate from shrinking too quickly.