]> granicus.if.org Git - liblinear/commit
Two changes in newton.cpp
authorChih-Jen Lin <cjlin@csie.ntu.edu.tw>
Fri, 16 Oct 2020 12:40:20 +0000 (20:40 +0800)
committerChih-Jen Lin <cjlin@csie.ntu.edu.tw>
Fri, 16 Oct 2020 12:40:20 +0000 (20:40 +0800)
commit07208b8beb4bc6545fcca2182734e0963cdcedaa
tree24697a11e307adc318a58e16479b260144fd22ff
parentc5019d78ff4f208d19aeb347e5adbfe3e77d2035
Two changes in newton.cpp

- in the previous version, the output is like

init f 1.403e+07
iter  1 f 5.390e+06 |g| 6.197e+05 CG   2 step_size 1.00e+00

we indeed print

f(w_k) |g(w_{k-1})|

So |g| 6.197e+05 is the grad at f(0) = 1.403e+07.

The output is changed to

init f 1.403e+07 |g| 6.197e+05
iter  1 f 5.390e+06 |g| 2.118e+05 CG   2 step_size 1.00e+00
iter  2 f 1.925e+06 |g| 7.244e+04 CG   4 step_size 1.00e+00

Each line shows the new f and |g| after an iteration with
CG steps and line search step_size

- in pcg(), we calculate

        alpha = zTr/ddot_(&n, d, &inc, Hd, &inc);

before the stopping condition based on quadratic approximations.
But after the previous CG step, the new zTr and dHd may both be zero
(or very close to zero). Then 0/0 may occur. In such a situation CG
should stop. Now a safeguard check is added:

+ dHd = ddot_(&n, d, &inc, Hd, &inc);
+ // avoid 0/0 in getting alpha
+ if (dHd <= 1.0e-16)
+ break;
newton.cpp