https://github.com/kul-forbes/ForBES
Revision dc65c2366e10a76b7166228adb65acb9a20d68a0 authored by Pantelis Sopasakis on 05 March 2018, 20:56:03 UTC, committed by GitHub on 05 March 2018, 20:56:03 UTC
crash of Forbes on Matlab 2017a
2 parent s 2d876d9 + 8253a09
Raw File
Tip revision: dc65c2366e10a76b7166228adb65acb9a20d68a0 authored by Pantelis Sopasakis on 05 March 2018, 20:56:03 UTC
Merge pull request #3 from Zilleplus/master
Tip revision: dc65c23
Direction_cgprp.m
% CG method of Polak-Ribiere-Polyak

function [dir, tau0, cache] = Direction_cgprp(prob, opt, it, restart, sk, yk, v, cache)

sk = sk(:);
yk = yk(:);
v = v(:);

if it == 1 || restart
    dir = -v; % Initially use steepest descent direction
    tau0 = 1.0/norm(dir, inf);
else
    beta = max((v'*yk)/cache.sqnorm_prev_v,0);
    dir = -v + beta*cache.prev_dir;
    if dir'*v >= 0 % restart if not descent direction
        dir = -v;
        tau0 = 1.0/norm(dir, inf);
        cache.cntSkip = cache.cntSkip+1;
    else
        tau0 = (sk'*sk)/(sk'*yk);
    end
end

cache.sqnorm_prev_v = norm(v)^2;
cache.prev_dir = dir;

end
back to top