From 416b0fd0d5ca29e2acd696cec26778f6f4527cf0 Mon Sep 17 00:00:00 2001 From: stevenj Date: Tue, 11 Nov 2008 00:57:23 -0500 Subject: [PATCH] fix xtol test in sbplx darcs-hash:20081111055723-c8de0-ccf13dd14cb29b1278db5fdec22ae833c6798530.gz --- neldermead/sbplx.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/neldermead/sbplx.c b/neldermead/sbplx.c index cc39941..1d20480 100644 --- a/neldermead/sbplx.c +++ b/neldermead/sbplx.c @@ -187,8 +187,19 @@ nlopt_result sbplx_minimize(int n, nlopt_func f, void *f_data, goto done; } if (nlopt_stop_x(stop, x, xprev)) { - ret = NLOPT_XTOL_REACHED; - goto done; + int j; + /* as explained in Rowan's thesis, it is important + to check |xstep| as well as |x-xprev|, since if + the step size is too large (in early iterations), + the inner Nelder-Mead may not make much progress */ + for (j = 0; j < n; ++j) + if (fabs(xstep[j]) * psi > stop->xtol_abs[j] + && fabs(xstep[j]) * psi > stop->xtol_rel * fabs(x[j])) + break; + if (j == n) { + ret = NLOPT_XTOL_REACHED; + goto done; + } } /* compute change in optimal point */ -- 2.30.2