From: stevenj Date: Tue, 17 Nov 2009 20:49:52 +0000 (-0500) Subject: detect singular case in BOBYQA X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=ed0eaab9534d43f6f8254f4c771d1d509b30069c;p=nlopt.git detect singular case in BOBYQA darcs-hash:20091117204952-c8de0-431f828a31642f18f4394f438e3bdb94128288ac.gz --- diff --git a/bobyqa/bobyqa.c b/bobyqa/bobyqa.c index f341333..51f5ddb 100644 --- a/bobyqa/bobyqa.c +++ b/bobyqa/bobyqa.c @@ -2747,6 +2747,12 @@ L360: /* L500: */ suma += zmat[knew + jj * zmat_dim1] * zmat[k + jj * zmat_dim1]; } + if (nlopt_isinf(suma)) { + /* SGJ: detect singularity here (happend if we run + for too many iterations) ... is there another way to recover? */ + rc = NLOPT_ROUNDOFF_LIMITED; + goto L720; + } sumb = zero; i__2 = *n; for (j = 1; j <= i__2; ++j) { diff --git a/test/testopt.cpp b/test/testopt.cpp index 18a5a1e..4d73c01 100644 --- a/test/testopt.cpp +++ b/test/testopt.cpp @@ -210,8 +210,11 @@ static int test_function(int ifunc) printf("Minimum at x = ["); for (i = 0; i < func.n; ++i) printf(" %g", x[i]); printf("]\n"); - printf("|f - minf| = %g, |f - minf| / |minf| = %e\n", - fabs(minf - func.minf), fabs(minf - func.minf) / fabs(func.minf)); + if (func.minf == 0) + printf("|f - minf| = %g\n", fabs(minf - func.minf)); + else + printf("|f - minf| = %g, |f - minf| / |minf| = %e\n", + fabs(minf - func.minf), fabs(minf - func.minf) / fabs(func.minf)); total_err += fabs(minf - func.minf); if (fabs(minf - func.minf) > max_err) max_err = fabs(minf - func.minf);