Certainly! Implementing the Wolfe conditions generally involves two parts: the sufficient decrease condition (also known as the Armijo condition, which you already have) and the curvature condition. The Wolfe conditions ensure both a sufficient decrease in the function value and sufficient progress along the gradient direction.
Here's how you can modify the gradient_method_armijo function to incorporate the Wolfe rule:
function [x, fun_val, x_hist] = gradient_method_wolfe(f, g, x0, alpha_init, epsilon, sigma, beta, c2)
% Gradient method with Wolfe rule line search
%
% INPUT
%=======================================
% f ......... objective function
% g ......... gradient of the objective function
% x0......... initial point
% alpha_init. initial step size
% epsilon ... tolerance parameter
% sigma ..... sufficient decrease parameter (0 < sigma < 1)
% beta ...... backtracking parameter (0 < beta < 1)
% c2 ........ curvature condition parameter (sigma < c2 < 1)
% OUTPUT
%=======================================
% x ......... optimal solution (up to a tolerance)
% of min f(x)
% fun_val ... optimal function value
% x_hist .... history of points
x = x0;
grad = g(x);
d = -grad;
x_hist = x0';
iter = 0;
while (norm(grad) > epsilon)
iter = iter + 1;
% Initialize step size
alpha = alpha_init;
% Backtracking with Wolfe conditions
while true
if f(x + alpha * d) > f(x) + sigma * alpha * grad' * d
alpha = beta * alpha; % Armijo condition not satisfied, reduce step size
elseif g(x + alpha * d)' * d < c2 * grad' * d
alpha = beta * alpha; % Curvature condition not satisfied, reduce step size
else
break; % Both conditions are satisfied
end
end
% Update x
x = x + alpha * d;
fun_val = f(x);
grad = g(x);
d = -grad;
x_hist = [x_hist; x']; % Store the history of x
fprintf('iter_number = %3d norm_grad = %2.6f fun_val = %2.6f alpha = %2.6f\n', iter, norm(grad), fun_val, alpha);
end
end
Explanation:
-
Inputs & Outputs: We added a new input parameter c2 for the curvature condition, which should satisfy sigma < c2 < 1.
-
Wolfe Conditions:
- Armijo (Sufficient Decrease) Condition: This is the same condition used previously.
- Curvature Condition: Ensures that the derivative in the direction of the line search is sufficiently flat, indicating progress.
-
Line Search:
- The loop continues to adjust
alpha using backtracking (multiplying by beta) until both the Armijo condition and the curvature condition are satisfied.
Now, the function uses the Wolfe rule for line search, ensuring convergence under mild conditions. You can use this function to optimize objective functions requiring smoothness and gradient information.