2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-21 04:24:59 +02:00
|
|
|
template<typename Functor, typename Scalar>
|
|
|
|
|
int ei_lmdif(
|
|
|
|
|
Matrix< Scalar, Dynamic, 1 > &x,
|
|
|
|
|
Matrix< Scalar, Dynamic, 1 > &fvec,
|
|
|
|
|
int &nfev,
|
|
|
|
|
Matrix< Scalar, Dynamic, Dynamic > &fjac,
|
|
|
|
|
VectorXi &ipvt,
|
|
|
|
|
Matrix< Scalar, Dynamic, 1 > &qtf,
|
|
|
|
|
Matrix< Scalar, Dynamic, 1 > &diag,
|
|
|
|
|
int mode=1,
|
|
|
|
|
Scalar factor = 100.,
|
|
|
|
|
int maxfev = 400,
|
|
|
|
|
Scalar ftol = ei_sqrt(epsilon<Scalar>()),
|
|
|
|
|
Scalar xtol = ei_sqrt(epsilon<Scalar>()),
|
|
|
|
|
Scalar gtol = Scalar(0.),
|
|
|
|
|
Scalar epsfcn = Scalar(0.),
|
|
|
|
|
int nprint=0
|
|
|
|
|
)
|
2009-08-19 18:38:45 +02:00
|
|
|
{
|
2009-08-21 04:24:59 +02:00
|
|
|
const int m = fvec.size(), n = x.size();
|
|
|
|
|
Matrix< Scalar, Dynamic, 1 >
|
|
|
|
|
wa1(n), wa2(n), wa3(n),
|
|
|
|
|
wa4(m);
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-21 04:24:59 +02:00
|
|
|
ipvt.resize(n);
|
2009-08-23 06:16:05 +02:00
|
|
|
fjac.resize(m, n);
|
2009-08-21 04:24:59 +02:00
|
|
|
diag.resize(n);
|
|
|
|
|
qtf.resize(n);
|
2009-08-19 18:38:45 +02:00
|
|
|
|
|
|
|
|
/* Local variables */
|
2009-08-21 00:26:37 +02:00
|
|
|
int i, j, l;
|
2009-08-20 21:10:28 +02:00
|
|
|
Scalar par, sum;
|
2009-08-19 18:38:45 +02:00
|
|
|
int iter;
|
2009-08-20 21:10:28 +02:00
|
|
|
Scalar temp, temp1, temp2;
|
2009-08-19 18:38:45 +02:00
|
|
|
int iflag;
|
2009-08-20 21:10:28 +02:00
|
|
|
Scalar delta;
|
|
|
|
|
Scalar ratio;
|
|
|
|
|
Scalar fnorm, gnorm;
|
|
|
|
|
Scalar pnorm, xnorm, fnorm1, actred, dirder, prered;
|
2009-08-19 18:38:45 +02:00
|
|
|
int info;
|
|
|
|
|
|
|
|
|
|
/* Function Body */
|
|
|
|
|
info = 0;
|
|
|
|
|
iflag = 0;
|
2009-08-21 00:23:26 +02:00
|
|
|
nfev = 0;
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* check the input parameters for errors. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-23 06:16:05 +02:00
|
|
|
if (n <= 0 || m < n || ftol < 0. || xtol < 0. ||
|
2009-08-20 23:36:03 +02:00
|
|
|
gtol < 0. || maxfev <= 0 || factor <= 0.) {
|
|
|
|
|
goto L300;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
2009-08-23 05:55:43 +02:00
|
|
|
if (mode == 2)
|
|
|
|
|
for (j = 0; j < n; ++j)
|
|
|
|
|
if (diag[j] <= 0.)
|
|
|
|
|
goto L300;
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* evaluate the function at the starting point */
|
|
|
|
|
/* and calculate its norm. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-23 04:57:48 +02:00
|
|
|
iflag = Functor::f(x, fvec);
|
2009-08-21 00:23:26 +02:00
|
|
|
nfev = 1;
|
2009-08-19 18:38:45 +02:00
|
|
|
if (iflag < 0) {
|
2009-08-20 23:36:03 +02:00
|
|
|
goto L300;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
2009-08-21 04:24:59 +02:00
|
|
|
fnorm = fvec.stableNorm();
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* initialize levenberg-marquardt parameter and iteration counter. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
|
|
|
|
par = 0.;
|
|
|
|
|
iter = 1;
|
|
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* beginning of the outer loop. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
|
|
|
|
L30:
|
|
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* calculate the jacobian matrix. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-23 04:06:16 +02:00
|
|
|
iflag = ei_fdjac2<Functor,Scalar>(x, fvec, fjac, epsfcn, wa4);
|
2009-08-21 00:23:26 +02:00
|
|
|
nfev += n;
|
2009-08-19 18:38:45 +02:00
|
|
|
if (iflag < 0) {
|
2009-08-20 23:36:03 +02:00
|
|
|
goto L300;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
2009-08-21 04:24:59 +02:00
|
|
|
/* if requested, call Functor::f to enable printing of iterates. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
|
|
|
|
if (nprint <= 0) {
|
2009-08-20 23:36:03 +02:00
|
|
|
goto L40;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
iflag = 0;
|
|
|
|
|
if ((iter - 1) % nprint == 0) {
|
2009-08-23 04:57:48 +02:00
|
|
|
iflag = Functor::debug(x, fvec);
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
if (iflag < 0) {
|
2009-08-20 23:36:03 +02:00
|
|
|
goto L300;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
L40:
|
|
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* compute the qr factorization of the jacobian. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-23 06:16:05 +02:00
|
|
|
ei_qrfac<Scalar>(m, n, fjac.data(), fjac.rows(), true, ipvt.data(), n, wa1.data(), wa2.data(), wa3.data());
|
2009-08-21 04:24:59 +02:00
|
|
|
ipvt.cwise()-=1; // qrfac() creates ipvt with fortran convetion (1->n), convert it to c (0->n-1)
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* on the first iteration and if mode is 1, scale according */
|
|
|
|
|
/* to the norms of the columns of the initial jacobian. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
|
|
|
|
if (iter != 1) {
|
2009-08-20 23:36:03 +02:00
|
|
|
goto L80;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
if (mode == 2) {
|
2009-08-20 23:36:03 +02:00
|
|
|
goto L60;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
2009-08-21 04:24:59 +02:00
|
|
|
for (j = 0; j < n; ++j) {
|
2009-08-20 23:36:03 +02:00
|
|
|
diag[j] = wa2[j];
|
|
|
|
|
if (wa2[j] == 0.) {
|
|
|
|
|
diag[j] = 1.;
|
|
|
|
|
}
|
|
|
|
|
/* L50: */
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
L60:
|
|
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* on the first iteration, calculate the norm of the scaled x */
|
|
|
|
|
/* and initialize the step bound delta. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-23 05:55:43 +02:00
|
|
|
wa3 = diag.cwise() * x;
|
2009-08-21 04:24:59 +02:00
|
|
|
xnorm = wa3.stableNorm();;
|
2009-08-19 18:38:45 +02:00
|
|
|
delta = factor * xnorm;
|
|
|
|
|
if (delta == 0.) {
|
2009-08-20 23:36:03 +02:00
|
|
|
delta = factor;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
L80:
|
|
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* form (q transpose)*fvec and store the first n components in */
|
|
|
|
|
/* qtf. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-23 05:55:43 +02:00
|
|
|
wa4 = fvec;
|
2009-08-21 04:24:59 +02:00
|
|
|
for (j = 0; j < n; ++j) {
|
2009-08-23 06:16:05 +02:00
|
|
|
if (fjac(j,j) == 0.) {
|
2009-08-20 23:36:03 +02:00
|
|
|
goto L120;
|
|
|
|
|
}
|
|
|
|
|
sum = 0.;
|
2009-08-21 04:24:59 +02:00
|
|
|
for (i = j; i < m; ++i) {
|
2009-08-23 06:16:05 +02:00
|
|
|
sum += fjac(i,j) * wa4[i];
|
2009-08-20 23:36:03 +02:00
|
|
|
/* L100: */
|
|
|
|
|
}
|
2009-08-23 06:16:05 +02:00
|
|
|
temp = -sum / fjac(j,j);
|
2009-08-21 04:24:59 +02:00
|
|
|
for (i = j; i < m; ++i) {
|
2009-08-23 06:16:05 +02:00
|
|
|
wa4[i] += fjac(i,j) * temp;
|
2009-08-20 23:36:03 +02:00
|
|
|
/* L110: */
|
|
|
|
|
}
|
2009-08-19 18:38:45 +02:00
|
|
|
L120:
|
2009-08-23 06:16:05 +02:00
|
|
|
fjac(j,j) = wa1[j];
|
2009-08-20 23:36:03 +02:00
|
|
|
qtf[j] = wa4[j];
|
|
|
|
|
/* L130: */
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* compute the norm of the scaled gradient. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
|
|
|
|
gnorm = 0.;
|
|
|
|
|
if (fnorm == 0.) {
|
2009-08-20 23:36:03 +02:00
|
|
|
goto L170;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
2009-08-21 04:24:59 +02:00
|
|
|
for (j = 0; j < n; ++j) {
|
2009-08-20 23:36:03 +02:00
|
|
|
l = ipvt[j];
|
2009-08-23 06:16:05 +02:00
|
|
|
if (wa2[l] != 0.) {
|
|
|
|
|
sum = 0.;
|
|
|
|
|
for (i = 0; i <= j; ++i)
|
|
|
|
|
sum += fjac(i,j) * (qtf[i] / fnorm);
|
|
|
|
|
/* Computing MAX */
|
|
|
|
|
gnorm = std::max(gnorm, ei_abs(sum / wa2[l]));
|
2009-08-20 23:36:03 +02:00
|
|
|
}
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
L170:
|
|
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* test for convergence of the gradient norm. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
|
|
|
|
if (gnorm <= gtol) {
|
2009-08-20 23:36:03 +02:00
|
|
|
info = 4;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
if (info != 0) {
|
2009-08-20 23:36:03 +02:00
|
|
|
goto L300;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* rescale if necessary. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
|
|
|
|
if (mode == 2) {
|
2009-08-20 23:36:03 +02:00
|
|
|
goto L190;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
2009-08-21 04:24:59 +02:00
|
|
|
for (j = 0; j < n; ++j) /* Computing MAX */
|
2009-08-22 05:29:33 +02:00
|
|
|
diag[j] = std::max(diag[j], wa2[j]);
|
2009-08-19 18:38:45 +02:00
|
|
|
L190:
|
|
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* beginning of the inner loop. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
|
|
|
|
L200:
|
|
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* determine the levenberg-marquardt parameter. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-21 04:24:59 +02:00
|
|
|
ipvt.cwise()+=1; // lmpar() expects the fortran convention (as qrfac provides)
|
2009-08-23 06:16:05 +02:00
|
|
|
ei_lmpar<Scalar>(n, fjac.data(), fjac.rows(), ipvt.data(), diag.data(), qtf.data(), delta,
|
2009-08-22 07:37:23 +02:00
|
|
|
par, wa1.data(), wa2.data(), wa3.data(), wa4.data());
|
2009-08-21 04:24:59 +02:00
|
|
|
ipvt.cwise()-=1;
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* store the direction p and x + p. calculate the norm of p. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-23 05:55:43 +02:00
|
|
|
wa1 = -wa1;
|
|
|
|
|
wa2 = x + wa1;
|
|
|
|
|
wa3 = diag.cwise() * wa1;
|
2009-08-21 04:24:59 +02:00
|
|
|
pnorm = wa3.stableNorm();
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* on the first iteration, adjust the initial step bound. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
|
|
|
|
if (iter == 1) {
|
2009-08-22 05:29:33 +02:00
|
|
|
delta = std::min(delta,pnorm);
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* evaluate the function at x + p and calculate its norm. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-23 04:57:48 +02:00
|
|
|
iflag = Functor::f(wa2, wa4);
|
2009-08-21 00:23:26 +02:00
|
|
|
++nfev;
|
2009-08-19 18:38:45 +02:00
|
|
|
if (iflag < 0) {
|
2009-08-20 23:36:03 +02:00
|
|
|
goto L300;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
2009-08-21 04:24:59 +02:00
|
|
|
fnorm1 = wa4.stableNorm();
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* compute the scaled actual reduction. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
|
|
|
|
actred = -1.;
|
2009-08-22 05:29:33 +02:00
|
|
|
if (Scalar(.1) * fnorm1 < fnorm) /* Computing 2nd power */
|
2009-08-20 23:56:13 +02:00
|
|
|
actred = 1. - ei_abs2(fnorm1 / fnorm);
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* compute the scaled predicted reduction and */
|
|
|
|
|
/* the scaled directional derivative. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-21 04:24:59 +02:00
|
|
|
for (j = 0; j < n; ++j) {
|
2009-08-20 23:36:03 +02:00
|
|
|
wa3[j] = 0.;
|
|
|
|
|
l = ipvt[j];
|
|
|
|
|
temp = wa1[l];
|
2009-08-21 04:24:59 +02:00
|
|
|
for (i = 0; i <= j; ++i) {
|
2009-08-23 06:16:05 +02:00
|
|
|
wa3[i] += fjac(i,j) * temp;
|
2009-08-20 23:36:03 +02:00
|
|
|
/* L220: */
|
|
|
|
|
}
|
|
|
|
|
/* L230: */
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
2009-08-21 04:24:59 +02:00
|
|
|
temp1 = ei_abs2(wa3.stableNorm() / fnorm);
|
|
|
|
|
temp2 = ei_abs2(ei_sqrt(par) * pnorm / fnorm);
|
2009-08-20 23:36:03 +02:00
|
|
|
/* Computing 2nd power */
|
2009-08-22 05:29:33 +02:00
|
|
|
prered = temp1 + temp2 / Scalar(.5);
|
2009-08-21 01:24:04 +02:00
|
|
|
dirder = -(temp1 + temp2);
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* compute the ratio of the actual to the predicted */
|
|
|
|
|
/* reduction. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
|
|
|
|
ratio = 0.;
|
|
|
|
|
if (prered != 0.) {
|
2009-08-20 23:36:03 +02:00
|
|
|
ratio = actred / prered;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* update the step bound. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-22 05:29:33 +02:00
|
|
|
if (ratio > Scalar(.25)) {
|
2009-08-20 23:36:03 +02:00
|
|
|
goto L240;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
if (actred >= 0.) {
|
2009-08-22 05:29:33 +02:00
|
|
|
temp = Scalar(.5);
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
if (actred < 0.) {
|
2009-08-22 05:29:33 +02:00
|
|
|
temp = Scalar(.5) * dirder / (dirder + Scalar(.5) * actred);
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
2009-08-22 05:29:33 +02:00
|
|
|
if (Scalar(.1) * fnorm1 >= fnorm || temp < Scalar(.1)) {
|
|
|
|
|
temp = Scalar(.1);
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
2009-08-20 23:36:03 +02:00
|
|
|
/* Computing MIN */
|
2009-08-22 05:29:33 +02:00
|
|
|
delta = temp * std::min(delta, pnorm / Scalar(.1));
|
2009-08-19 18:38:45 +02:00
|
|
|
par /= temp;
|
|
|
|
|
goto L260;
|
|
|
|
|
L240:
|
2009-08-22 05:29:33 +02:00
|
|
|
if (par != 0. && ratio < Scalar(.75)) {
|
2009-08-20 23:36:03 +02:00
|
|
|
goto L250;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
2009-08-22 05:29:33 +02:00
|
|
|
delta = pnorm / Scalar(.5);
|
|
|
|
|
par = Scalar(.5) * par;
|
2009-08-19 18:38:45 +02:00
|
|
|
L250:
|
|
|
|
|
L260:
|
|
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* test for successful iteration. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-22 05:29:33 +02:00
|
|
|
if (ratio < Scalar(1e-4)) {
|
2009-08-20 23:36:03 +02:00
|
|
|
goto L290;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* successful iteration. update x, fvec, and their norms. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-23 05:55:43 +02:00
|
|
|
x = wa2;
|
|
|
|
|
wa2 = diag.cwise() * x;
|
|
|
|
|
fvec = wa4;
|
2009-08-21 04:24:59 +02:00
|
|
|
xnorm = wa2.stableNorm();
|
2009-08-19 18:38:45 +02:00
|
|
|
fnorm = fnorm1;
|
|
|
|
|
++iter;
|
|
|
|
|
L290:
|
|
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* tests for convergence. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-22 05:29:33 +02:00
|
|
|
if (ei_abs(actred) <= ftol && prered <= ftol && Scalar(.5) * ratio <= 1.) {
|
2009-08-20 23:36:03 +02:00
|
|
|
info = 1;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
if (delta <= xtol * xnorm) {
|
2009-08-20 23:36:03 +02:00
|
|
|
info = 2;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
2009-08-22 05:29:33 +02:00
|
|
|
if (ei_abs(actred) <= ftol && prered <= ftol && Scalar(.5) * ratio <= 1. && info
|
2009-08-20 23:36:03 +02:00
|
|
|
== 2) {
|
|
|
|
|
info = 3;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
if (info != 0) {
|
2009-08-20 23:36:03 +02:00
|
|
|
goto L300;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* tests for termination and stringent tolerances. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-21 00:23:26 +02:00
|
|
|
if (nfev >= maxfev) {
|
2009-08-20 23:36:03 +02:00
|
|
|
info = 5;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
2009-08-22 05:29:33 +02:00
|
|
|
if (ei_abs(actred) <= epsilon<Scalar>() && prered <= epsilon<Scalar>() && Scalar(.5) * ratio <= 1.) {
|
2009-08-20 23:36:03 +02:00
|
|
|
info = 6;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
2009-08-20 21:10:28 +02:00
|
|
|
if (delta <= epsilon<Scalar>() * xnorm) {
|
2009-08-20 23:36:03 +02:00
|
|
|
info = 7;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
2009-08-20 21:10:28 +02:00
|
|
|
if (gnorm <= epsilon<Scalar>()) {
|
2009-08-20 23:36:03 +02:00
|
|
|
info = 8;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
if (info != 0) {
|
2009-08-20 23:36:03 +02:00
|
|
|
goto L300;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* end of the inner loop. repeat if iteration unsuccessful. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
2009-08-22 05:29:33 +02:00
|
|
|
if (ratio < Scalar(1e-4)) {
|
2009-08-20 23:36:03 +02:00
|
|
|
goto L200;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* end of the outer loop. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
|
|
|
|
goto L30;
|
|
|
|
|
L300:
|
|
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* termination, either normal or user imposed. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
|
|
|
|
if (iflag < 0) {
|
2009-08-20 23:36:03 +02:00
|
|
|
info = iflag;
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
iflag = 0;
|
|
|
|
|
if (nprint > 0) {
|
2009-08-23 04:57:48 +02:00
|
|
|
iflag = Functor::debug(x, fvec);
|
2009-08-19 18:38:45 +02:00
|
|
|
}
|
|
|
|
|
return info;
|
|
|
|
|
|
2009-08-20 23:36:03 +02:00
|
|
|
/* last card of subroutine lmdif. */
|
2009-08-19 18:38:45 +02:00
|
|
|
|
|
|
|
|
} /* lmdif_ */
|
|
|
|
|
|