%% backtrack line search
function [alpha, num_feval] = backtrack_line_search(fun, x, pk, alpha)
if nargin < 4
    a = 1;
end
rho = 0.5;
c1 = 0.0001;
num_feval = 0;

[f g] = feval(fun, x);

while(1)
    L_alpha = feval(fun, x+alpha*pk);
    num_feval = num_feval + 1;
    if (g'*pk > 0) break; end % accent direction, return
    if L_alpha > f + alpha*c1*g'*pk
        alpha = rho*alpha;
    else
        break;
    end
end

end