This commit is contained in:
Thomas Capricelli 2009-08-25 19:57:42 +02:00
parent d38d4709bc
commit 84f2c451e5
2 changed files with 31 additions and 44 deletions

View File

@ -117,7 +117,6 @@ HybridNonLinearSolver<FunctorType,Scalar>::solve(
int sing; int sing;
int iter; int iter;
Scalar temp; Scalar temp;
int iflag;
Scalar delta; Scalar delta;
int jeval; int jeval;
int ncsuc; int ncsuc;
@ -129,7 +128,6 @@ HybridNonLinearSolver<FunctorType,Scalar>::solve(
Scalar actred, prered; Scalar actred, prered;
/* Function Body */ /* Function Body */
iflag = 0;
nfev = 0; nfev = 0;
njev = 0; njev = 0;
@ -145,9 +143,9 @@ HybridNonLinearSolver<FunctorType,Scalar>::solve(
/* evaluate the function at the starting point */ /* evaluate the function at the starting point */
/* and calculate its norm. */ /* and calculate its norm. */
iflag = functor.f(x, fvec);
nfev = 1; nfev = 1;
if (iflag < 0) return UserAksed; if ( functor.f(x, fvec) < 0)
return UserAksed;
fnorm = fvec.stableNorm(); fnorm = fvec.stableNorm();
/* initialize iteration counter and monitors. */ /* initialize iteration counter and monitors. */
@ -165,10 +163,9 @@ HybridNonLinearSolver<FunctorType,Scalar>::solve(
/* calculate the jacobian matrix. */ /* calculate the jacobian matrix. */
iflag = functor.df(x, fjac); if ( functor.df(x, fjac) < 0)
++njev;
if (iflag < 0)
return UserAksed; return UserAksed;
++njev;
/* compute the qr factorization of the jacobian. */ /* compute the qr factorization of the jacobian. */
@ -255,9 +252,9 @@ HybridNonLinearSolver<FunctorType,Scalar>::solve(
/* evaluate the function at x + p and calculate its norm. */ /* evaluate the function at x + p and calculate its norm. */
iflag = functor.f(wa2, wa4); if ( functor.f(wa2, wa4) < 0)
return UserAksed;
++nfev; ++nfev;
if (iflag < 0) return UserAksed;
fnorm1 = wa4.stableNorm(); fnorm1 = wa4.stableNorm();
/* compute the scaled actual reduction. */ /* compute the scaled actual reduction. */
@ -440,7 +437,7 @@ HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiff(
int sing; int sing;
int iter; int iter;
Scalar temp; Scalar temp;
int msum, iflag; int msum;
Scalar delta; Scalar delta;
int jeval; int jeval;
int ncsuc; int ncsuc;
@ -453,7 +450,6 @@ HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiff(
/* Function Body */ /* Function Body */
iflag = 0;
nfev = 0; nfev = 0;
/* check the input parameters for errors. */ /* check the input parameters for errors. */
@ -468,9 +464,8 @@ HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiff(
/* evaluate the function at the starting point */ /* evaluate the function at the starting point */
/* and calculate its norm. */ /* and calculate its norm. */
iflag = functor.f(x, fvec);
nfev = 1; nfev = 1;
if (iflag < 0) if ( functor.f(x, fvec) < 0)
return UserAksed; return UserAksed;
fnorm = fvec.stableNorm(); fnorm = fvec.stableNorm();
@ -495,11 +490,9 @@ HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiff(
/* calculate the jacobian matrix. */ /* calculate the jacobian matrix. */
iflag = ei_fdjac1(functor, x, fvec, fjac, if (ei_fdjac1(functor, x, fvec, fjac, nb_of_subdiagonals, nb_of_superdiagonals, epsfcn) <0)
nb_of_subdiagonals, nb_of_superdiagonals, epsfcn);
nfev += msum;
if (iflag < 0)
return UserAksed; return UserAksed;
nfev += msum;
/* compute the qr factorization of the jacobian. */ /* compute the qr factorization of the jacobian. */
@ -586,9 +579,9 @@ HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiff(
/* evaluate the function at x + p and calculate its norm. */ /* evaluate the function at x + p and calculate its norm. */
iflag = functor.f(wa2, wa4); if ( functor.f(wa2, wa4) < 0)
return UserAksed;
++nfev; ++nfev;
if (iflag < 0) return UserAksed;
fnorm1 = wa4.stableNorm(); fnorm1 = wa4.stableNorm();
/* compute the scaled actual reduction. */ /* compute the scaled actual reduction. */

View File

@ -145,14 +145,12 @@ LevenbergMarquardt<FunctorType,Scalar>::minimize(
Scalar par, sum; Scalar par, sum;
int iter; int iter;
Scalar temp, temp1, temp2; Scalar temp, temp1, temp2;
int iflag;
Scalar delta; Scalar delta;
Scalar ratio; Scalar ratio;
Scalar fnorm, gnorm; Scalar fnorm, gnorm;
Scalar pnorm, xnorm, fnorm1, actred, dirder, prered; Scalar pnorm, xnorm, fnorm1, actred, dirder, prered;
/* Function Body */ /* Function Body */
iflag = 0;
nfev = 0; nfev = 0;
njev = 0; njev = 0;
@ -169,9 +167,9 @@ LevenbergMarquardt<FunctorType,Scalar>::minimize(
/* evaluate the function at the starting point */ /* evaluate the function at the starting point */
/* and calculate its norm. */ /* and calculate its norm. */
iflag = functor.f(x, fvec);
nfev = 1; nfev = 1;
if (iflag < 0) return UserAsked; if ( functor.f(x, fvec) < 0)
return UserAsked;
fnorm = fvec.stableNorm(); fnorm = fvec.stableNorm();
/* initialize levenberg-marquardt parameter and iteration counter. */ /* initialize levenberg-marquardt parameter and iteration counter. */
@ -185,9 +183,9 @@ LevenbergMarquardt<FunctorType,Scalar>::minimize(
/* calculate the jacobian matrix. */ /* calculate the jacobian matrix. */
iflag = functor.df(x, fjac); if (functor.df(x, fjac) < 0)
return UserAsked;
++njev; ++njev;
if (iflag < 0) return UserAsked;
/* compute the qr factorization of the jacobian. */ /* compute the qr factorization of the jacobian. */
@ -278,9 +276,9 @@ LevenbergMarquardt<FunctorType,Scalar>::minimize(
/* evaluate the function at x + p and calculate its norm. */ /* evaluate the function at x + p and calculate its norm. */
iflag = functor.f(wa2, wa4); if ( functor.f(wa2, wa4) < 0)
return UserAsked;
++nfev; ++nfev;
if (iflag < 0) return UserAsked;
fnorm1 = wa4.stableNorm(); fnorm1 = wa4.stableNorm();
/* compute the scaled actual reduction. */ /* compute the scaled actual reduction. */
@ -429,14 +427,12 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeNumericalDiff(
Scalar par, sum; Scalar par, sum;
int iter; int iter;
Scalar temp, temp1, temp2; Scalar temp, temp1, temp2;
int iflag;
Scalar delta; Scalar delta;
Scalar ratio; Scalar ratio;
Scalar fnorm, gnorm; Scalar fnorm, gnorm;
Scalar pnorm, xnorm, fnorm1, actred, dirder, prered; Scalar pnorm, xnorm, fnorm1, actred, dirder, prered;
/* Function Body */ /* Function Body */
iflag = 0;
nfev = 0; nfev = 0;
/* check the input parameters for errors. */ /* check the input parameters for errors. */
@ -451,9 +447,9 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeNumericalDiff(
/* evaluate the function at the starting point */ /* evaluate the function at the starting point */
/* and calculate its norm. */ /* and calculate its norm. */
iflag = functor.f(x, fvec);
nfev = 1; nfev = 1;
if (iflag < 0) return UserAsked; if ( functor.f(x, fvec) < 0)
return UserAsked;
fnorm = fvec.stableNorm(); fnorm = fvec.stableNorm();
/* initialize levenberg-marquardt parameter and iteration counter. */ /* initialize levenberg-marquardt parameter and iteration counter. */
@ -467,9 +463,9 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeNumericalDiff(
/* calculate the jacobian matrix. */ /* calculate the jacobian matrix. */
iflag = ei_fdjac2(functor, x, fvec, fjac, epsfcn); if ( ei_fdjac2(functor, x, fvec, fjac, epsfcn) < 0)
return UserAsked;
nfev += n; nfev += n;
if (iflag < 0) return UserAsked;
/* compute the qr factorization of the jacobian. */ /* compute the qr factorization of the jacobian. */
@ -560,9 +556,9 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeNumericalDiff(
/* evaluate the function at x + p and calculate its norm. */ /* evaluate the function at x + p and calculate its norm. */
iflag = functor.f(wa2, wa4); if ( functor.f(wa2, wa4) < 0)
return UserAsked;
++nfev; ++nfev;
if (iflag < 0) return UserAsked;
fnorm1 = wa4.stableNorm(); fnorm1 = wa4.stableNorm();
/* compute the scaled actual reduction. */ /* compute the scaled actual reduction. */
@ -712,14 +708,12 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorage(
Scalar par, sum; Scalar par, sum;
int sing, iter; int sing, iter;
Scalar temp, temp1, temp2; Scalar temp, temp1, temp2;
int iflag;
Scalar delta; Scalar delta;
Scalar ratio; Scalar ratio;
Scalar fnorm, gnorm; Scalar fnorm, gnorm;
Scalar pnorm, xnorm, fnorm1, actred, dirder, prered; Scalar pnorm, xnorm, fnorm1, actred, dirder, prered;
/* Function Body */ /* Function Body */
iflag = 0;
nfev = 0; nfev = 0;
njev = 0; njev = 0;
@ -736,9 +730,9 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorage(
/* evaluate the function at the starting point */ /* evaluate the function at the starting point */
/* and calculate its norm. */ /* and calculate its norm. */
iflag = functor.f(x, fvec);
nfev = 1; nfev = 1;
if (iflag < 0) return UserAsked; if ( functor.f(x, fvec) < 0)
return UserAsked;
fnorm = fvec.stableNorm(); fnorm = fvec.stableNorm();
/* initialize levenberg-marquardt parameter and iteration counter. */ /* initialize levenberg-marquardt parameter and iteration counter. */
@ -757,12 +751,12 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorage(
qtf.fill(0.); qtf.fill(0.);
fjac.fill(0.); fjac.fill(0.);
iflag = 2; int rownb = 2;
for (i = 0; i < m; ++i) { for (i = 0; i < m; ++i) {
if (functor.df(x, wa3, iflag) < 0) return UserAsked; if (functor.df(x, wa3, rownb) < 0) return UserAsked;
temp = fvec[i]; temp = fvec[i];
ei_rwupdt<Scalar>(n, fjac.data(), fjac.rows(), wa3.data(), qtf.data(), &temp, wa1.data(), wa2.data()); ei_rwupdt<Scalar>(n, fjac.data(), fjac.rows(), wa3.data(), qtf.data(), &temp, wa1.data(), wa2.data());
++iflag; ++rownb;
} }
++njev; ++njev;
@ -861,9 +855,9 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorage(
/* evaluate the function at x + p and calculate its norm. */ /* evaluate the function at x + p and calculate its norm. */
iflag = functor.f(wa2, wa4); if ( functor.f(wa2, wa4) < 0)
return UserAsked;
++nfev; ++nfev;
if (iflag < 0) return UserAsked;
fnorm1 = wa4.stableNorm(); fnorm1 = wa4.stableNorm();
/* compute the scaled actual reduction. */ /* compute the scaled actual reduction. */