使用非精确线搜索Armijo算法确定步长的最速下降法(MATLAB)

Armijo算法实现:

function mk = armijo( fun, xk, rho, sigma, gk )

assert( rho > 0 && rho < 1 );
assert( sigma > 0 && sigma < 0.5 );

mk = 0; max_mk = 100;

while mk <= max_mk
    x = xk - rho^mk * gk;
    if feval( fun, x ) <= feval( fun, xk ) - sigma * rho^mk * norm( gk )^2
        break;
    end
    mk = mk + 1;
end

return;
最速下降法实现:
function [opt_x, opt_f, k] = grad_descent( fun_obj, fun_grad, x0 )

max_iter = 5000;    % max number of iterations
EPS = 1e-5;         % threshold of gradient norm

% Armijo parameters
rho = 0.5; sigma = 0.2;

% initialization
k = 0; xk = x0;

while k < max_iter
    
    k = k + 1;
    
    gk = feval( fun_grad, xk ); % gradient vector
    dk = -1 * gk;               % search direction
    
    if norm( dk ) < EPS
        break;
    end
    
   

你可能感兴趣的:(Optimization,MATLAB,matlab,算法,fun,function,vector,search)