From f4ea7bbc7c176185f8fa05f7d81890ea428f1afa Mon Sep 17 00:00:00 2001 From: b92paul Date: Tue, 21 Feb 2017 16:52:58 +0800 Subject: [PATCH] Add new region updating rule in TRON method The new rule will change delta to delta*sigma3 when actred >= eta2*prered and step reach trust region boundary in CG iterations. Following lines are the changes: - Add new argument reach_boundary in TRON::trcg method to return whether step from CG iterations reached boundary or not. - Add new enlarge rule using the result reach_boundary returned from TRON::trcg in TRON::tron method. --- tron.cpp | 14 +++++++++++--- tron.h | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tron.cpp b/tron.cpp index 3c32d7f..6c7e3c7 100644 --- a/tron.cpp +++ b/tron.cpp @@ -91,9 +91,10 @@ void TRON::tron(double *w) iter = 1; double *w_new = new double[n]; + bool reach_boundary; while (iter <= max_iter && search) { - cg_iter = trcg(delta, g, s, r); + cg_iter = trcg(delta, g, s, r, &reach_boundary); memcpy(w_new, w, sizeof(double)*n); daxpy_(&n, &one, s, &inc, w_new, &inc); @@ -124,7 +125,12 @@ void TRON::tron(double *w) else if (actred < eta2*prered) delta = max(sigma1*delta, min(alpha*snorm, sigma3*delta)); else - delta = max(delta, min(alpha*snorm, sigma3*delta)); + { + if (reach_boundary) + delta = sigma3*delta; + else + delta = max(delta, min(alpha*snorm, sigma3*delta)); + } info("iter %2d act %5.3e pre %5.3e delta %5.3e f %5.3e |g| %5.3e CG %3d\n", iter, actred, prered, delta, f, gnorm, cg_iter); @@ -163,7 +169,7 @@ void TRON::tron(double *w) delete[] s; } -int TRON::trcg(double delta, double *g, double *s, double *r) +int TRON::trcg(double delta, double *g, double *s, double *r, bool* reach_boundary) { int i, inc = 1; int n = fun_obj->get_nr_variable(); @@ -172,6 +178,7 @@ int TRON::trcg(double delta, double *g, double *s, double *r) double *Hd = new double[n]; double rTr, rnewTrnew, alpha, beta, cgtol; + *reach_boundary = false; for (i=0; i delta) { info("cg reaches trust region boundary\n"); + *reach_boundary = true; alpha = -alpha; daxpy_(&n, &alpha, d, &inc, s, &inc); diff --git a/tron.h b/tron.h index 56002dc..86b6392 100644 --- a/tron.h +++ b/tron.h @@ -22,7 +22,7 @@ public: void set_print_string(void (*i_print) (const char *buf)); private: - int trcg(double delta, double *g, double *s, double *r); + int trcg(double delta, double *g, double *s, double *r, bool* reach_boundary); double norm_inf(int n, double *x); double eps; -- 2.40.0