Christos Choutouridis 65fd57a70f WIP
2024-11-26 18:13:35 +02:00

26 lines
696 B
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, x0)
% Calculates the best step based on amijo method
%
% f(xk γk*∇f(xk)) ≤ f(xk) σ*γk*∥∇f(xk)∥^2
%
% f: Objective function
% x0: Initial (x,y) point
% beta: beta factor in (0, 1)
% signam: sigma factor in (0,1)
global amijo_beta
global amijo_sigma
gamma = 1; % Start with a step size of 1
grad = grad_f(x0(1), x0(2));
% Perform Armijo line search
while f(x0(1) - gamma * grad(1), x0(2) - gamma * grad(2)) > ...
f(x0(1), x0(2)) - amijo_sigma * gamma * norm(grad)^2
gamma = amijo_beta * gamma; % Reduce step size
end
end