fix tests : we perform slightly worse because we do use one more function

evaluation in our numericaldiff than what (c)minpack did
This commit is contained in:
Thomas Capricelli 2009-09-28 04:13:57 +02:00
parent d912034565
commit 7968737247
3 changed files with 11 additions and 9 deletions

View File

@ -55,7 +55,7 @@ public:
); );
static Status lmdif1( static Status lmdif1(
FunctorType &_functor, FunctorType &functor,
Matrix< Scalar, Dynamic, 1 > &x, Matrix< Scalar, Dynamic, 1 > &x,
int *nfev, int *nfev,
const Scalar tol = ei_sqrt(epsilon<Scalar>()) const Scalar tol = ei_sqrt(epsilon<Scalar>())
@ -200,9 +200,13 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeOneStep(
/* calculate the jacobian matrix. */ /* calculate the jacobian matrix. */
if (functor.df(x, fjac) < 0) int df_ret = functor.df(x, fjac);
if (df_ret<0)
return UserAsked; return UserAsked;
++njev; if (df_ret>0)
// numerical diff, we evaluated the function df_ret times
nfev += df_ret;
else njev++;
/* compute the qr factorization of the jacobian. */ /* compute the qr factorization of the jacobian. */
@ -702,10 +706,8 @@ LevenbergMarquardt<FunctorType,Scalar>::lmdif1(
lm.parameters.maxfev = 200*(n+1); lm.parameters.maxfev = 200*(n+1);
Status info = Status(lm.minimize(x)); Status info = Status(lm.minimize(x));
if (nfev) if (nfev)
* nfev = lm.nfev; * nfev = lm.nfev;
return info; return info;
} }

View File

@ -74,6 +74,7 @@ public:
val1.resize(Functor::values()); val1.resize(Functor::values());
val2.resize(Functor::values()); val2.resize(Functor::values());
// initialization
switch(mode) { switch(mode) {
case Forward: case Forward:
// compute f(x) // compute f(x)
@ -86,8 +87,7 @@ public:
assert(false); assert(false);
}; };
/* Function Body */ // Function Body
for (int j = 0; j < n; ++j) { for (int j = 0; j < n; ++j) {
h = eps * ei_abs(x[j]); h = eps * ei_abs(x[j]);
if (h == 0.) { if (h == 0.) {

View File

@ -561,7 +561,7 @@ void testLmdif1()
// check return value // check return value
VERIFY( 1 == info); VERIFY( 1 == info);
VERIFY(nfev==21); VERIFY(nfev==26);
// check norm // check norm
functor(x, fvec); functor(x, fvec);
@ -592,7 +592,7 @@ void testLmdif()
// check return values // check return values
VERIFY( 1 == info); VERIFY( 1 == info);
VERIFY(lm.nfev==21); VERIFY(lm.nfev==26);
// check norm // check norm
fnorm = lm.fvec.blueNorm(); fnorm = lm.fvec.blueNorm();