define and use struct Parameters

This commit is contained in:
Thomas Capricelli
2009-08-25 21:50:01 +02:00
parent d13bcdc891
commit e465ea82e1
3 changed files with 187 additions and 147 deletions

View File

@@ -181,7 +181,8 @@ void testLmder()
// do the computation
lmder_functor functor;
LevenbergMarquardt<lmder_functor> lm(functor);
info = lm.minimize(x, nfev, njev, diag);
LevenbergMarquardt<lmder_functor>::Parameters parameters;
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return values
VERIFY( 1 == info);
@@ -290,19 +291,19 @@ void testHybrj1()
void testHybrj()
{
const int n=9;
int info, nfev=0, njev=0, mode;
int info, nfev=0, njev=0;
VectorXd x(n), diag(n);
/* the following starting values provide a rough fit. */
x.setConstant(n, -1.);
mode = 2;
diag.setConstant(n, 1.);
// do the computation
hybrj_functor functor;
HybridNonLinearSolver<hybrj_functor> solver(functor);
info = solver.solve(x, nfev, njev, diag, mode);
HybridNonLinearSolver<hybrj_functor>::Parameters parameters;
info = solver.solve(x, nfev, njev, diag, parameters, 2);
// check return value
VERIFY( 1 == info);
@@ -372,7 +373,7 @@ void testHybrd1()
void testHybrd()
{
const int n=9;
int info, nfev=0, ml, mu, mode;
int info, nfev=0, ml, mu;
VectorXd x, diag(n);
/* the following starting values provide a rough fit. */
@@ -380,13 +381,13 @@ void testHybrd()
ml = 1;
mu = 1;
mode = 2;
diag.setConstant(n, 1.);
// do the computation
hybrd_functor functor;
HybridNonLinearSolver<hybrd_functor> solver(functor);
info = solver.solveNumericalDiff(x, nfev, diag, mode, ml, mu);
HybridNonLinearSolver<hybrd_functor>::Parameters parameters;
info = solver.solveNumericalDiff(x, nfev, diag, parameters, 2, ml, mu);
// check return value
VERIFY( 1 == info);
@@ -484,7 +485,8 @@ void testLmstr()
// do the computation
lmstr_functor functor;
LevenbergMarquardt<lmstr_functor> lm(functor);
info = lm.minimizeOptimumStorage(x, nfev, njev, diag);
LevenbergMarquardt<lmstr_functor>::Parameters parameters;
info = lm.minimizeOptimumStorage(x, nfev, njev, diag, parameters);
// check return values
VERIFY( 1 == info);
@@ -570,7 +572,8 @@ void testLmdif()
// do the computation
lmdif_functor functor;
LevenbergMarquardt<lmdif_functor> lm(functor);
info = lm.minimizeNumericalDiff(x, nfev, diag);
LevenbergMarquardt<lmdif_functor>::Parameters parameters;
info = lm.minimizeNumericalDiff(x, nfev, diag, parameters);
// check return values
VERIFY( 1 == info);
@@ -655,7 +658,8 @@ void testNistChwirut2(void)
// do the computation
chwirut2_functor functor;
LevenbergMarquardt<chwirut2_functor> lm(functor);
info = lm.minimize(x, nfev, njev, diag);
LevenbergMarquardt<chwirut2_functor>::Parameters parameters;
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -673,8 +677,10 @@ void testNistChwirut2(void)
*/
x<< 0.15, 0.008, 0.010;
// do the computation
info = lm.minimize(x, nfev, njev, diag,
1, 100., 400, 1.E6*epsilon<double>(), 1.E6*epsilon<double>());
parameters = LevenbergMarquardt<chwirut2_functor>::Parameters(); // get default back
parameters.ftol = 1.E6*epsilon<double>();
parameters.xtol = 1.E6*epsilon<double>();
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -733,7 +739,8 @@ void testNistMisra1a(void)
// do the computation
misra1a_functor functor;
LevenbergMarquardt<misra1a_functor> lm(functor);
info = lm.minimize(x, nfev, njev, diag);
LevenbergMarquardt<misra1a_functor>::Parameters parameters;
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -750,7 +757,7 @@ void testNistMisra1a(void)
*/
x<< 250., 0.0005;
// do the computation
info = lm.minimize(x, nfev, njev, diag);
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -819,7 +826,8 @@ void testNistHahn1(void)
// do the computation
hahn1_functor functor;
LevenbergMarquardt<hahn1_functor> lm(functor);
info = lm.minimize(x, nfev, njev, diag);
LevenbergMarquardt<hahn1_functor>::Parameters parameters;
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -841,7 +849,7 @@ void testNistHahn1(void)
*/
x<< .1, -.1, .005, -.000001, -.005, .0001, -.0000001;
// do the computation
info = lm.minimize(x, nfev, njev, diag);
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -905,7 +913,8 @@ void testNistMisra1d(void)
// do the computation
misra1d_functor functor;
LevenbergMarquardt<misra1d_functor> lm(functor);
info = lm.minimize(x, nfev, njev, diag);
LevenbergMarquardt<misra1d_functor>::Parameters parameters;
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 3 == info);
@@ -922,7 +931,7 @@ void testNistMisra1d(void)
*/
x<< 450., 0.0003;
// do the computation
info = lm.minimize(x, nfev, njev, diag);
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -983,7 +992,8 @@ void testNistLanczos1(void)
// do the computation
lanczos1_functor functor;
LevenbergMarquardt<lanczos1_functor> lm(functor);
info = lm.minimize(x, nfev, njev, diag);
LevenbergMarquardt<lanczos1_functor>::Parameters parameters;
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 2 == info);
@@ -1004,7 +1014,7 @@ void testNistLanczos1(void)
*/
x<< 0.5, 0.7, 3.6, 4.2, 4., 6.3;
// do the computation
info = lm.minimize(x, nfev, njev, diag);
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 2 == info);
@@ -1069,7 +1079,8 @@ void testNistRat42(void)
// do the computation
rat42_functor functor;
LevenbergMarquardt<rat42_functor> lm(functor);
info = lm.minimize(x, nfev, njev, diag);
LevenbergMarquardt<rat42_functor>::Parameters parameters;
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -1087,7 +1098,7 @@ void testNistRat42(void)
*/
x<< 75., 2.5, 0.07;
// do the computation
info = lm.minimize(x, nfev, njev, diag);
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -1147,7 +1158,8 @@ void testNistMGH10(void)
// do the computation
MGH10_functor functor;
LevenbergMarquardt<MGH10_functor> lm(functor);
info = lm.minimize(x, nfev, njev, diag);
LevenbergMarquardt<MGH10_functor>::Parameters parameters;
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 2 == info);
@@ -1165,7 +1177,7 @@ void testNistMGH10(void)
*/
x<< 0.02, 4000., 250.;
// do the computation
info = lm.minimize(x, nfev, njev, diag);
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 2 == info);
@@ -1223,8 +1235,11 @@ void testNistBoxBOD(void)
// do the computation
BoxBOD_functor functor;
LevenbergMarquardt<BoxBOD_functor> lm(functor);
info = lm.minimize(x, nfev, njev, diag,
1, 10., 400, 1E6*epsilon<double>(), 1E6*epsilon<double>());
LevenbergMarquardt<BoxBOD_functor>::Parameters parameters;
parameters.ftol = 1.E6*epsilon<double>();
parameters.xtol = 1.E6*epsilon<double>();
parameters.factor = 10.;
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -1241,8 +1256,10 @@ void testNistBoxBOD(void)
*/
x<< 100., 0.75;
// do the computation
info = lm.minimize(x, nfev, njev, diag,
1, 100., 14000, epsilon<double>(), epsilon<double>());
parameters = LevenbergMarquardt<BoxBOD_functor>::Parameters(); // get default back
parameters.ftol = epsilon<double>();
parameters.xtol = epsilon<double>();
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -1301,8 +1318,11 @@ void testNistMGH17(void)
// do the computation
MGH17_functor functor;
LevenbergMarquardt<MGH17_functor> lm(functor);
info = lm.minimize(x, nfev, njev, diag,
1, 100., 5000, epsilon<double>(), epsilon<double>());
LevenbergMarquardt<MGH17_functor>::Parameters parameters;
parameters.ftol = epsilon<double>();
parameters.xtol = epsilon<double>();
parameters.maxfev = 1000;
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -1322,7 +1342,8 @@ void testNistMGH17(void)
*/
x<< 0.5 ,1.5 ,-1 ,0.01 ,0.02;
// do the computation
info = lm.minimize(x, nfev, njev, diag);
parameters = LevenbergMarquardt<MGH17_functor>::Parameters(); // get default back
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -1387,8 +1408,9 @@ void testNistMGH09(void)
// do the computation
MGH09_functor functor;
LevenbergMarquardt<MGH09_functor> lm(functor);
info = lm.minimize(x, nfev, njev, diag,
1, 100., 5000);
LevenbergMarquardt<MGH09_functor>::Parameters parameters;
parameters.maxfev = 1000;
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -1407,7 +1429,8 @@ void testNistMGH09(void)
*/
x<< 0.25, 0.39, 0.415, 0.39;
// do the computation
info = lm.minimize(x, nfev, njev, diag);
parameters = LevenbergMarquardt<MGH09_functor>::Parameters();
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -1469,7 +1492,9 @@ void testNistBennett5(void)
// do the computation
Bennett5_functor functor;
LevenbergMarquardt<Bennett5_functor> lm(functor);
info = lm.minimize(x, nfev, njev, diag, 1, 100., 5000);
LevenbergMarquardt<Bennett5_functor>::Parameters parameters;
parameters.maxfev = 1000;
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -1486,7 +1511,8 @@ void testNistBennett5(void)
*/
x<< -1500., 45., 0.85;
// do the computation
info = lm.minimize(x, nfev, njev, diag);
parameters = LevenbergMarquardt<Bennett5_functor>::Parameters();
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -1554,8 +1580,10 @@ void testNistThurber(void)
// do the computation
thurber_functor functor;
LevenbergMarquardt<thurber_functor> lm(functor);
info = lm.minimize(x, nfev, njev, diag,
1, 100., 400, 1.E4*epsilon<double>(), 1.E4*epsilon<double>());
LevenbergMarquardt<thurber_functor>::Parameters parameters;
parameters.ftol = 1.E4*epsilon<double>();
parameters.xtol = 1.E4*epsilon<double>();
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -1577,8 +1605,10 @@ void testNistThurber(void)
*/
x<< 1300 ,1500 ,500 ,75 ,1 ,0.4 ,0.05 ;
// do the computation
info = lm.minimize(x, nfev, njev, diag,
1, 100., 400, 1.E4*epsilon<double>(), 1.E4*epsilon<double>());
parameters = LevenbergMarquardt<thurber_functor>::Parameters();
parameters.ftol = 1.E4*epsilon<double>();
parameters.xtol = 1.E4*epsilon<double>();
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -1643,8 +1673,10 @@ void testNistRat43(void)
// do the computation
rat43_functor functor;
LevenbergMarquardt<rat43_functor> lm(functor);
info = lm.minimize(x, nfev, njev, diag,
1, 100., 400, 1.E6*epsilon<double>(), 1.E6*epsilon<double>());
LevenbergMarquardt<rat43_functor>::Parameters parameters;
parameters.ftol = 1.E6*epsilon<double>();
parameters.xtol = 1.E6*epsilon<double>();
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -1663,8 +1695,10 @@ void testNistRat43(void)
*/
x<< 700., 5., 0.75, 1.3;
// do the computation
info = lm.minimize(x, nfev, njev, diag,
1, 100., 400, 1.E5*epsilon<double>(), 1.E5*epsilon<double>());
parameters = LevenbergMarquardt<rat43_functor>::Parameters(); // get default back
parameters.ftol = 1.E5*epsilon<double>();
parameters.xtol = 1.E5*epsilon<double>();
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -1727,7 +1761,8 @@ void testNistEckerle4(void)
// do the computation
eckerle4_functor functor;
LevenbergMarquardt<eckerle4_functor> lm(functor);
info = lm.minimize(x, nfev, njev, diag);
LevenbergMarquardt<eckerle4_functor>::Parameters parameters;
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);
@@ -1745,7 +1780,7 @@ void testNistEckerle4(void)
*/
x<< 1.5, 5., 450.;
// do the computation
info = lm.minimize(x, nfev, njev, diag);
info = lm.minimize(x, nfev, njev, diag, parameters);
// check return value
VERIFY( 1 == info);