THMMY's "Optimization Techniques" course assignments.
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

gamma_armijo.m 1.0 KiB

1234567891011121314151617181920212223242526272829303132
  1. function [gamma] = gamma_armijo(f, grad_f, dk, xk)
  2. % Calculates the best step based on amijo method
  3. %
  4. % f(xk​+ γk*dk) ≤ f(xk) + σ * γk * dk^T * ∇f(xk)
  5. % γk = β*γk_0
  6. %
  7. % f: Objective function
  8. % grad_fun: Gradient function of f
  9. % dk: Current value of selected direction -∇f or -inv{H}*∇f or -inv{H + lI}*∇f
  10. % xk: Current point (x,y)
  11. % beta: beta factor in [0.1, 0.5]
  12. % signam: sigma factor in (0, 0.1]
  13. global amijo_beta
  14. global amijo_sigma
  15. gf = grad_f(xk);
  16. gamma = 1; % Start with a step size of 1
  17. % Perform Armijo line search
  18. while f(xk + gamma * dk) > f(xk) + amijo_sigma * gamma * dk * gf
  19. %while f(xk(1) + gamma * dk(1), xk(2) + gamma * dk(2)) > ...
  20. % f(xk(1), xk(2)) + amijo_sigma * gamma * norm(dk)^2
  21. gamma = amijo_beta * gamma; % Reduce step size
  22. if gamma < 1e-12 % Safeguard to prevent infinite reduction
  23. warning('Armijo step size became too small.');
  24. break;
  25. end
  26. end
  27. end