The Optimal Path: Steepest Descent with Exact Line Search

Exploring the mechanics of unconstrained optimization for quadratic functions

steepest-descent-exact-line-search-mtzg960s2 Sources

Published · References and presentation revised

Save

Key Insights into Optimization

  • Exact Line Search Derivation: For the given quadratic function, the optimal step length \( \alpha_k \) in steepest descent is explicitly derived using the gradient and Hessian, enabling precise minimization along the search direction.
  • Algorithm Implementation and Convergence: The Steepest Descent method, when combined with exact line search, efficiently converges to the global minimum, characterized by a near-zero gradient and a positive definite Hessian.
  • Optimality Conditions: The unique global minimum for this convex quadratic function is confirmed by satisfying both first-order (zero gradient) and second-order (positive definite Hessian) optimality conditions.

This comprehensive guide delves into the optimization problem of minimizing the quadratic function \( f(x, y) = (x + 3y - 6)^2 + (3x + y + 4)^2 \). We will meticulously explore the theoretical underpinnings and practical implementation of the steepest descent method with exact line search. This includes deriving the optimal step length, outlining the algorithmic steps with a robust stopping criterion, evaluating optimality conditions, and visualizing the optimization process through contour plots and convergence graphs.

Illustration of Steepest Descent method on a quadratic function's contour plot.

Visual representation of the steepest descent path on a quadratic function.


Deciphering the Objective Function

The objective function given is \( f(x, y) = (x + 3y - 6)^2 + (3x + y + 4)^2 \). This is a quadratic function, which is particularly well-suited for optimization methods due to its convexity. Understanding its structure is crucial for deriving the gradient and Hessian.

Gradient and Hessian of the Objective Function

To perform steepest descent, we first need to compute the gradient of \( f(x, y) \). The gradient, denoted as \( \nabla f(x, y) \), is a vector of partial derivatives with respect to each variable:

\[ \frac{\partial f}{\partial x} = 2(x + 3y - 6)(1) + 2(3x + y + 4)(3) = 2x + 6y - 12 + 18x + 6y + 24 = 20x + 12y + 12 \] \[ \frac{\partial f}{\partial y} = 2(x + 3y - 6)(3) + 2(3x + y + 4)(1) = 6x + 18y - 36 + 6x + 2y + 8 = 12x + 20y - 28 \]

Thus, the gradient vector is:

\[ \nabla f(x, y) = \begin{bmatrix} 20x + 12y + 12 \ 12x + 20y - 28 \end{bmatrix} \]

Next, we compute the Hessian matrix, \( H_f(x, y) = \nabla^2 f(x, y) \), which contains the second-order partial derivatives. For a quadratic function, the Hessian is constant.

\[ \frac{\partial^2 f}{\partial x^2} = \frac{\partial}{\partial x}(20x + 12y + 12) = 20 \] \[ \frac{\partial^2 f}{\partial y^2} = \frac{\partial}{\partial y}(12x + 20y - 28) = 20 \] \[ \frac{\partial^2 f}{\partial x \partial y} = \frac{\partial}{\partial y}(20x + 12y + 12) = 12 \] \[ \frac{\partial^2 f}{\partial y \partial x} = \frac{\partial}{\partial x}(12x + 20y - 28) = 12 \]

So, the Hessian matrix is:

\[ H_f(x, y) = \begin{bmatrix} 20 & 12 \ 12 & 20 \end{bmatrix} \]

The constant and positive definite nature of this Hessian (as we will demonstrate later) confirms that the function \( f(x, y) \) is strictly convex, ensuring a unique global minimum.


Deriving the Optimal Step Length for Exact Line Search

In the steepest descent method, we move in the direction opposite to the gradient. For a given point \( x_k = [x_k, y_k]^T \) and search direction \( p_k = -\nabla f(x_k) \), we want to find the optimal step length \( \alpha_k \) that minimizes the function along this direction. This is achieved by minimizing \( \phi(\alpha) = f(x_k + \alpha p_k) \) with respect to \( \alpha \).

The optimal step length \( \alpha_k \) can be found by setting the derivative of \( \phi(\alpha) \) with respect to \( \alpha \) to zero:

\[ \frac{d\phi}{d\alpha} = \nabla f(x_k + \alpha p_k)^T p_k = 0 \]

For a quadratic function \( f(x) = \frac{1}{2}x^T Q x + c^T x + d \), where \( Q \) is the Hessian, the optimal step length \( \alpha_k \) for the steepest descent direction \( p_k = -\nabla f(x_k) = -g_k \) simplifies to a closed-form expression:

\[ \alpha_k = \frac{g_k^T g_k}{g_k^T H g_k} \]

Where \( g_k = \nabla f(x_k) \) is the gradient at point \( x_k \), and \( H \) is the Hessian matrix. This formula provides a computationally efficient way to determine \( \alpha_k \) at each iteration without needing to solve a univariate minimization problem numerically.

Implementing the Step Length Calculation (Conceptual MATLAB Function)

A MATLAB function for calculating the optimal step length would take the current point and the gradient at that point as inputs, returning the optimal \( \alpha \). Considering the general quadratic form, the function would look something like this:


        function alpha_k = calculateOptimalAlpha(x_k, grad_f_k, H)
            % x_k: current point [x; y]
            % grad_f_k: gradient at x_k
            % H: Hessian matrix (constant for quadratic functions)

            % Ensure inputs are column vectors
            if size(x_k, 2) > 1
                x_k = x_k';
            end
            if size(grad_f_k, 2) > 1
                grad_f_k = grad_f_k';
            end

            numerator = grad_f_k' * grad_f_k;
            denominator = grad_f_k' * H * grad_f_k;

            % Avoid division by zero in case of zero gradient (already at minimum)
            if denominator == 0
                alpha_k = 0;
            else
                alpha_k = numerator / denominator;
            end
        end
    

This conceptual MATLAB function precisely implements the derived formula for the optimal step length, which is crucial for the efficiency and correctness of the steepest descent algorithm.


Steepest Descent with Exact Line Search Implementation

The steepest descent method iteratively refines an initial guess to find the minimum of a function. With exact line search, each step taken is the optimal one along the current gradient direction.

Visualization of a gradient descent path converging to a minimum in 2D.

Example of gradient descent trajectory on a 2D surface.

Algorithm Steps and Stopping Criterion

The steepest descent algorithm with exact line search proceeds as follows:

  1. Initialization: Choose an initial point \( x_0 \), set iteration counter \( k=0 \), and define a small tolerance \( \epsilon \) for the stopping criterion.
  2. Compute Gradient: Calculate the gradient \( g_k = \nabla f(x_k) \) at the current point \( x_k \).
  3. Check Stopping Criterion: If the norm of the gradient \( \|g_k\| \) is less than \( \epsilon \), or if the relative change in gradient norm \( \|g_k\| / \|g_0\| \) is less than \( \epsilon \), stop the algorithm. The current point \( x_k \) is considered the optimal point.
  4. Determine Search Direction: The search direction is the negative gradient: \( p_k = -g_k \).
  5. Calculate Optimal Step Length: Compute \( \alpha_k \) using the exact line search formula derived earlier: \( \alpha_k = \frac{g_k^T g_k}{g_k^T H g_k} \).
  6. Update Point: Update the current point to the next iteration: \( x_{k+1} = x_k + \alpha_k p_k \).
  7. Increment Counter: Set \( k = k+1 \) and go back to Step 2.

A common and effective stopping criterion for optimization algorithms is to check the norm of the gradient. When \( \|\nabla f(x_k)\|_2 < \epsilon \), it implies that we are very close to a stationary point. For a convex function like ours, this stationary point is the global minimum.

MATLAB Implementation for Steepest Descent

The following MATLAB code encapsulates the steepest descent algorithm with exact line search:


        function [x_star, fval_star, path_history, fval_history] = steepest_descent_exact_line_search(x0, tol, maxIter)
            % x0: Initial guess (column vector)
            % tol: Tolerance for stopping criterion
            % maxIter: Maximum number of iterations

            % Define problem data
            A_matrix = [1, 3; 3, 1];
            b_vector = [6; -4];
            H_matrix = 2 * (A_matrix' * A_matrix); % Hessian of f, constant for quadratic

            % Define anonymous functions for gradient and objective
            grad_f = @(x) 2 * (A_matrix' * (A_matrix * x - b_vector));
            f = @(x) (A_matrix * x - b_vector)' * (A_matrix * x - b_vector);

            x_k = x0;
            path_history = x_k'; % Store initial point
            fval_history = f(x_k); % Store initial function value
            
            initial_grad_norm = norm(grad_f(x_k)); % For relative tolerance

            for iter = 1:maxIter
                g_k = grad_f(x_k);

                % Stopping criterion: Check if gradient norm is below tolerance
                if norm(g_k) < tol * initial_grad_norm || norm(g_k) < tol
                    break;
                end

                p_k = -g_k; % Steepest descent direction

                % Calculate optimal alpha using the derived formula
                numerator = g_k' * g_k;
                denominator = g_k' * H_matrix * g_k;

                if denominator == 0
                    alpha_k = 0; % Already at a minimum or flat region
                else
                    alpha_k = numerator / denominator;
                end

                x_k = x_k + alpha_k * p_k; % Update the point

                path_history = [path_history; x_k']; % Append current point to history
                fval_history = [fval_history; f(x_k)]; % Append current fval to history
            end

            x_star = x_k;
            fval_star = f(x_k);
        end
    

The code uses anonymous functions for

grad_f
and
f
for clarity and directly applies the derived optimal step length formula. The
path_history
and
fval_history
variables are crucial for visualizing the optimization process later.

Comparison with the Analytical Optimum

The analytical solution for the minimum of \( f(x,y) \) can be found by setting its gradient to zero. This leads to a system of linear equations:

\[ 20x + 12y + 12 = 0 \implies 5x + 3y = -3 \] \[ 12x + 20y - 28 = 0 \implies 3x + 5y = 7 \]

Solving this system yields the optimal point \( x^* = [-2.25, 2.75]^T \). When the MATLAB implementation is run with sufficient iterations and a small tolerance, the computed optimal point \( x_{\text{star}} \) should closely match this analytical solution, typically to machine precision. Discrepancies would indicate errors in the implementation of the algorithm or the line search.


Evaluating Optimality Conditions

For an unconstrained optimization problem, two primary conditions determine if a point is a local minimum: first-order necessary conditions and second-order sufficient conditions.

First-Order Necessary Condition

A point \( x^* \) is a stationary point if the gradient of the function at that point is zero: \( \nabla f(x^*) = 0 \). For our objective function, this means:

\[ 20x^* + 12y^* + 12 = 0 \] \[ 12x^* + 20y^* - 28 = 0 \]

As derived before, solving this system gives \( x^* = -2.25 \) and \( y^* = 2.75 \). At this point, both components of the gradient are zero, satisfying the first-order necessary condition.

Second-Order Sufficient Condition

For a stationary point to be a local minimum, the Hessian matrix evaluated at that point, \( H_f(x^*) \), must be positive definite. For our function, the Hessian is constant:

\[ H_f(x, y) = \begin{bmatrix} 20 & 12 \ 12 & 20 \end{bmatrix} \]

To check for positive definiteness, we can examine its eigenvalues. The characteristic equation is \( (20-\lambda)^2 - 12^2 = 0 \), which simplifies to \( \lambda^2 - 40\lambda + 256 = 0 \). The eigenvalues are \( \lambda_1 = 32 \) and \( \lambda_2 = 8 \). Since both eigenvalues are positive, the Hessian matrix is positive definite. This confirms that the stationary point \( (-2.25, 2.75) \) is indeed a strict local minimum. Because the function is convex, this local minimum is also the unique global minimum.

mindmap root["Optimization of f(x,y)"] Objective["f(x,y) = (x+3y-6)^2 + (3x+y+4)^2"] Gradient["Gradient #quot;g(x,y)#quot;"] PartialX["#8706;f/#8706;x = 20x + 12y + 12"] PartialY["#8706;f/#8706;y = 12x + 20y - 28"] Hessian["Hessian #quot;H#quot;"] HessianMatrix["[[20, 12], [12, 20]]"] PositiveDefinite["Positive Definite (Eigenvalues 8, 32 > 0)"] SteepestDescent["Steepest Descent Method"] SearchDirection["p_k = -g_k"] ExactLineSearch["#945;_k = (g_k^T g_k) / (g_k^T H g_k)"] IterationUpdate["x_{k+1} = x_k + #945;_k p_k"] OptimalityConditions["Optimality Conditions at x*"] FirstOrder["#8711;f(x*) = 0"] Solution["x* = [-2.25, 2.75]^T"] SecondOrder["Hessian #quot;H#quot; at x* is Positive Definite"] GlobalMinimum["Confirms Unique Global Minimum"] Visualization["Visualization"] ContourPlot["Function #quot;f#quot; Contours"] OptimizerPath["Iterates x_k Overlayed"] ConvergencePlot["f(x_k) vs. Iteration k"]

Mindmap illustrating the key components and relationships in optimizing the given quadratic function using the steepest descent method with exact line search.


Visualizing the Optimization Process

Visualizing the optimization process is critical for understanding the algorithm's behavior and convergence characteristics. This involves plotting the contour lines of the objective function and overlaying the path taken by the optimizer.

Contour Plot and Optimizer Steps

A contour plot of \( f(x,y) \) displays lines of constant function value, providing a landscape of the objective function. By plotting the sequence of points \( x_k \) generated by the steepest descent algorithm on this contour plot, we can see how the optimizer iteratively moves towards the minimum.


        % MATLAB Code for Contour Plot and Optimizer Steps
        % Assuming 'steepest_descent_exact_line_search' function is defined
        
        % Run the optimization
        x0 = [0; 0]; % Initial guess
        tol = 1e-6; % Tolerance
        maxIter = 100; % Maximum iterations
        [x_star, fval_star, path_history, fval_history] = steepest_descent_exact_line_search(x0, tol, maxIter);
        
        % Create a grid for the contour plot
        x_range = linspace(-4, 4, 100);
        y_range = linspace(-2, 6, 100);
        [X, Y] = meshgrid(x_range, y_range);
        
        % Calculate function values for the grid
        F_values = zeros(size(X));
        A_matrix = [1, 3; 3, 1];
        b_vector = [6; -4];
        for i = 1:size(X, 1)
            for j = 1:size(X, 2)
                current_x = [X(i, j); Y(i, j)];
                F_values(i, j) = (A_matrix * current_x - b_vector)' * (A_matrix * current_x - b_vector);
            end
        end
        
        figure;
        contour(X, Y, F_values, 20); % Plot 20 contour lines
        hold on;
        
        % Plot the path taken by the optimizer
        plot(path_history(:, 1), path_history(:, 2), '-o', 'LineWidth', 1.5, 'MarkerSize', 5, 'Color', '#388278');
        
        % Mark the optimal point
        plot(x_star(1), x_star(2), 'p', 'MarkerSize', 10, 'MarkerFaceColor', '#cc9900', 'MarkerEdgeColor', 'k');
        
        title('Steepest Descent Path on Contour Plot');
        xlabel('x');
        ylabel('y');
        legend('Contours', 'Optimizer Path', 'Optimal Point');
        grid on;
        hold off;
    

This MATLAB script first defines the search space using

meshgrid
and calculates function values for each point to create the contour plot. Then, it overlays the
path_history
obtained from the steepest descent algorithm, typically showing a zigzag path that efficiently navigates towards the central minimum of the elliptical contours.

Plotting the Convergence of the Function

To assess the convergence rate, we plot the objective function value \( f(x_k) \) at each iteration \( k \) against the iteration number. For well-behaved convex functions like ours, this plot usually shows a rapid decrease in the function value, often exhibiting linear convergence, especially in the initial steps, eventually flattening out as it approaches the minimum.


        % MATLAB Code for Convergence Plot
        % Assuming 'fval_history' is obtained from the optimization run
        
        figure;
        plot(0:length(fval_history)-1, fval_history, '-o', 'LineWidth', 1.5, 'Color', '#388278');
        title('Convergence of Objective Function Value');
        xlabel('Iteration Number (k)');
        ylabel('f(x_k)');
        grid on;
    

This plot provides direct evidence of the algorithm's effectiveness in reducing the objective function value over iterations, confirming that it is converging towards the minimum.


Summary of Optimization Characteristics

Here's a table summarizing the key aspects of the objective function and its optimization using steepest descent with exact line search.

Characteristic Description
Objective Function \( f(x,y) \) \( (x + 3y - 6)^2 + (3x + y + 4)^2 \) - A quadratic and strictly convex function.
Gradient \( \nabla f(x,y) \) \( \begin{bmatrix} 20x + 12y + 12 \ 12x + 20y - 28 \end{bmatrix} \) - Provides the direction of steepest ascent.
Hessian \( H_f \) \( \begin{bmatrix} 20 & 12 \ 12 & 20 \end{bmatrix} \) - Constant and positive definite, confirming convexity and a unique global minimum.
Optimal Step Length \( \alpha_k \) \( \frac{g_k^T g_k}{g_k^T H g_k} \) - Derived for exact line search, guarantees optimal movement along the search direction.
Steepest Descent Update Rule \( x_{k+1} = x_k - \alpha_k \nabla f(x_k) \) - Iteratively moves towards the minimum.
Optimal Point \( x^* \) \( [-2.25, 2.75]^T \) - The unique global minimum of the function.
First-Order Optimality \( \nabla f(x^*) = 0 \) - Satisfied at \( x^* \).
Second-Order Optimality \( H_f(x^*) \succ 0 \) - Hessian is positive definite, confirming \( x^* \) is a local minimum.

The YouTube video below offers a practical guide to implementing steepest descent in MATLAB, which aligns with the theoretical and implementation details discussed here, especially concerning the visualization of the optimization path.

This video demonstrates the implementation of the steepest descent algorithm in MATLAB, illustrating how to set up the problem and visualize the optimization steps, which is directly relevant to plotting the optimizer's path.


FAQ

What is the steepest descent method?
The steepest descent method is an iterative optimization algorithm for finding a local minimum of a function. It proceeds by taking steps proportional to the negative of the gradient of the function at the current point.
Why is exact line search important in steepest descent?
Exact line search determines the optimal step length at each iteration, ensuring that the function is minimized as much as possible along the current search direction. This typically leads to faster convergence compared to methods with fixed step sizes.
What are the optimality conditions for unconstrained optimization?
For a local minimum, the first-order necessary condition is that the gradient of the function must be zero. The second-order sufficient condition requires that the Hessian matrix at that point must be positive definite.
How does a contour plot help visualize optimization?
A contour plot displays lines of constant function value, effectively mapping the "landscape" of the objective function. Plotting the optimizer's path on this contour allows visualization of how the algorithm navigates this landscape to find the minimum.

Conclusion

The optimization of the given quadratic function \( f(x, y) = (x + 3y - 6)^2 + (3x + y + 4)^2 \) using the steepest descent method with exact line search provides a clear example of a powerful and efficient approach to unconstrained minimization. By accurately deriving the optimal step length formula, implementing the iterative algorithm, and verifying the necessary and sufficient optimality conditions, we confirm the method's ability to precisely locate the unique global minimum at \( [-2.25, 2.75]^T \). The visualizations of the optimizer's path on contour plots and the convergence of the objective function value per iteration offer compelling evidence of the algorithm's effectiveness and stable progression towards the optimal solution. This detailed analysis underscores the importance of both theoretical understanding and practical implementation in solving optimization problems.


Recommended Reading


Referenced Search Results

Discuss this answer