From: b92paul Date: Thu, 8 Mar 2018 07:02:51 +0000 (+0800) Subject: Fixed bug and optimize code in TRON::tron X-Git-Tag: v221~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eca3bd047f9a53e4f92f51ab753edf195a937e85;p=liblinear Fixed bug and optimize code in TRON::tron Variable "iter" and "w" won't change in the while loop of function TRON::tron when the direction does not lead to sufficient function-value decrease, so using expression "iter == 1" as a flag to initialize variables will cause problems in the first step. We introduce a new variable "delta_adjusted" to fix the bug. The function call "fun_obj->get_diagH(M)" and the calculation of "(1-alpha_pcg) I + alpha_pcg M" can be saved if "iter" and "w" remains the same. We move some lines of code to save the calculation. --- diff --git a/tron.cpp b/tron.cpp index d662d99..2d93dc3 100644 --- a/tron.cpp +++ b/tron.cpp @@ -103,17 +103,16 @@ void TRON::tron(double *w) if (gnorm <= eps*gnorm0) search = 0; - iter = 1; + fun_obj->get_diagH(M); + for(i=0; iget_diagH(M); - for(i=0; igrad(w, g); + fun_obj->get_diagH(M); + for(i=0; i