2025-03-05 10:53:15 +02:00

33 lines
1.1 KiB
Matlab
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function [gamma] = gamma_armijo(f, grad_f, dk, xk)
% Calculates the best step based on amijo method
%
% f(xk+ γk*dk) ≤ f(xk) + σ * γk * dk^T * ∇f(xk)
% γk = β*γk_0
%
% f: Objective function
% grad_fun: Gradient function of f
% dk: Current value of selected direction -∇f or -inv{H}*∇f or -inv{H + lI}*∇f
% xk: Current point (x,y)
% beta: beta factor in [0.1, 0.5]
% signam: sigma factor in (0, 0.1]
global amijo_beta
global amijo_sigma
gf = grad_f(xk(1), xk(2));
gamma = 1; % Start with a step size of 1
% Perform Armijo line search
while f(xk(1) + gamma * dk(1), xk(2) + gamma * dk(2)) > ...
f(xk(1), xk(2)) + amijo_sigma * gamma * dk' * gf
%while f(xk(1) + gamma * dk(1), xk(2) + gamma * dk(2)) > ...
% f(xk(1), xk(2)) + amijo_sigma * gamma * norm(dk)^2
gamma = amijo_beta * gamma; % Reduce step size
if gamma < 1e-12 % Safeguard to prevent infinite reduction
warning('Armijo step size became too small.');
break;
end
end
end