THMMY's "Optimization Techniques" course assignments.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

26 lines
696 B

  1. function [gamma] = gamma_armijo(f, grad_f, x0)
  2. % Calculates the best step based on amijo method
  3. %
  4. % f(xk​− γk*∇f(xk)) ≤ f(xk) − σ*γk*∥∇f(xk)∥^2
  5. %
  6. % f: Objective function
  7. % x0: Initial (x,y) point
  8. % beta: beta factor in (0, 1)
  9. % signam: sigma factor in (0,1)
  10. global amijo_beta
  11. global amijo_sigma
  12. gamma = 1; % Start with a step size of 1
  13. grad = grad_f(x0(1), x0(2));
  14. % Perform Armijo line search
  15. while f(x0(1) - gamma * grad(1), x0(2) - gamma * grad(2)) > ...
  16. f(x0(1), x0(2)) - amijo_sigma * gamma * norm(grad)^2
  17. gamma = amijo_beta * gamma; % Reduce step size
  18. end
  19. end