MCPcopy Create free account
hub / github.com/abess-team/abess / testNistMGH17

Function testNistMGH17

python/include/unsupported/test/NonLinearOptimization.cpp:1329–1386  ·  view source on GitHub ↗

http://www.itl.nist.gov/div898/strd/nls/data/mgh17.shtml

Source from the content-addressed store, hash-verified

1327
1328// http://www.itl.nist.gov/div898/strd/nls/data/mgh17.shtml
1329void testNistMGH17(void)
1330{
1331 const int n=5;
1332 int info;
1333
1334 VectorXd x(n);
1335
1336 /*
1337 * First try
1338 */
1339 x<< 50., 150., -100., 1., 2.;
1340 // do the computation
1341 MGH17_functor functor;
1342 LevenbergMarquardt<MGH17_functor> lm(functor);
1343 lm.parameters.ftol = NumTraits<double>::epsilon();
1344 lm.parameters.xtol = NumTraits<double>::epsilon();
1345 lm.parameters.maxfev = 1000;
1346 info = lm.minimize(x);
1347
1348 // check norm^2
1349 VERIFY_IS_APPROX(lm.fvec.squaredNorm(), 5.4648946975E-05);
1350 // check x
1351 VERIFY_IS_APPROX(x[0], 3.7541005211E-01);
1352 VERIFY_IS_APPROX(x[1], 1.9358469127E+00);
1353 VERIFY_IS_APPROX(x[2], -1.4646871366E+00);
1354 VERIFY_IS_APPROX(x[3], 1.2867534640E-02);
1355 VERIFY_IS_APPROX(x[4], 2.2122699662E-02);
1356
1357 // check return value
1358 VERIFY_IS_EQUAL(info, 2);
1359 ++g_test_level;
1360 VERIFY_IS_EQUAL(lm.nfev, 602); // 602
1361 VERIFY_IS_EQUAL(lm.njev, 545); // 545
1362 --g_test_level;
1363 VERIFY(lm.nfev < 602 * LM_EVAL_COUNT_TOL);
1364 VERIFY(lm.njev < 545 * LM_EVAL_COUNT_TOL);
1365
1366 /*
1367 * Second try
1368 */
1369 x<< 0.5 ,1.5 ,-1 ,0.01 ,0.02;
1370 // do the computation
1371 lm.resetParameters();
1372 info = lm.minimize(x);
1373
1374 // check return value
1375 VERIFY_IS_EQUAL(info, 1);
1376 VERIFY_IS_EQUAL(lm.nfev, 18);
1377 VERIFY_IS_EQUAL(lm.njev, 15);
1378 // check norm^2
1379 VERIFY_IS_APPROX(lm.fvec.squaredNorm(), 5.4648946975E-05);
1380 // check x
1381 VERIFY_IS_APPROX(x[0], 3.7541005211E-01);
1382 VERIFY_IS_APPROX(x[1], 1.9358469127E+00);
1383 VERIFY_IS_APPROX(x[2], -1.4646871366E+00);
1384 VERIFY_IS_APPROX(x[3], 1.2867534640E-02);
1385 VERIFY_IS_APPROX(x[4], 2.2122699662E-02);
1386}

Callers 1

Calls 3

minimizeMethod · 0.45
squaredNormMethod · 0.45
resetParametersMethod · 0.45

Tested by

no test coverage detected