From 1c498e7173ce3134eea41a8bcdcaf77b8a9a03dd Mon Sep 17 00:00:00 2001 From: Takeshi Enomoto Date: Sat, 20 Nov 2021 14:23:55 +0900 Subject: [PATCH 1/3] cg: always start line search with unit step length --- src/unconstrained/cg.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unconstrained/cg.cpp b/src/unconstrained/cg.cpp index 151117c..488fdab 100644 --- a/src/unconstrained/cg.cpp +++ b/src/unconstrained/cg.cpp @@ -158,7 +158,7 @@ optim::internal::cg_impl( Vec_t d_p = - grad_p + beta*d; - t_init = t * (OPTIM_MATOPS_DOT_PROD(grad,d) / OPTIM_MATOPS_DOT_PROD(grad_p,d_p)); + t_init = 1.0; grad = grad_p; From efbbdbbafb6029d10d5b5e2f137279a96643ac05 Mon Sep 17 00:00:00 2001 From: Takeshi Enomoto Date: Wed, 1 Dec 2021 14:19:14 +0900 Subject: [PATCH 2/3] cg.cpp: corrected step size and search direction for better convergence * revert to the initial step size estimation for each iteration * scale initial step size by gradient norm * use search direction from cg_update --- src/unconstrained/cg.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/unconstrained/cg.cpp b/src/unconstrained/cg.cpp index 488fdab..e097a97 100644 --- a/src/unconstrained/cg.cpp +++ b/src/unconstrained/cg.cpp @@ -128,7 +128,7 @@ optim::internal::cg_impl( // - double t_init = 1.0; // initial value for line search + double t_init = 1.0 / grad_err; // initial value for line search d = - grad; Vec_t x_p = x, grad_p = grad; @@ -158,11 +158,11 @@ optim::internal::cg_impl( Vec_t d_p = - grad_p + beta*d; - t_init = 1.0; + t_init = t * (OPTIM_MATOPS_DOT_PROD(grad,d) / OPTIM_MATOPS_DOT_PROD(grad_p,d_p)); grad = grad_p; - t = line_search_mt(t_init, x_p, grad_p, d, &wolfe_cons_1, &wolfe_cons_2, box_objfn, opt_data); + t = line_search_mt(t_init, x_p, grad_p, d_p, &wolfe_cons_1, &wolfe_cons_2, box_objfn, opt_data); // From 9011b4fdbe81d04dc0f55fcc941aebf1f57f4337 Mon Sep 17 00:00:00 2001 From: Takeshi Enomoto Date: Wed, 1 Dec 2021 14:50:29 +0900 Subject: [PATCH 3/3] cg: print x and grad after line search at step 0 --- src/unconstrained/cg.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unconstrained/cg.cpp b/src/unconstrained/cg.cpp index e097a97..508d95e 100644 --- a/src/unconstrained/cg.cpp +++ b/src/unconstrained/cg.cpp @@ -138,7 +138,7 @@ optim::internal::cg_impl( grad_err = OPTIM_MATOPS_L2NORM(grad_p); double rel_sol_change = OPTIM_MATOPS_L1NORM( OPTIM_MATOPS_ARRAY_DIV_ARRAY( (x_p - x), (OPTIM_MATOPS_ARRAY_ADD_SCALAR(OPTIM_MATOPS_ABS(x), 1.0e-08)) ) ); - OPTIM_CG_TRACE(0, grad_err, rel_sol_change, x, d, grad, 0.0); + OPTIM_CG_TRACE(0, grad_err, rel_sol_change, x_p, d, grad_p, 0.0); if (grad_err <= grad_err_tol) { init_out_vals = x_p;