misc cleaning

This commit is contained in:
Thomas Capricelli 2009-08-24 09:28:29 +02:00
parent 6e41f15fea
commit e65a7c7c70
5 changed files with 28 additions and 40 deletions

View File

@ -161,16 +161,13 @@ L120:
} }
for (j = 0; j < n; ++j) { for (j = 0; j < n; ++j) {
l = ipvt[j]; l = ipvt[j];
if (wa2[l] == 0.) { if (wa2[l] != 0.) {
goto L150;
}
sum = 0.; sum = 0.;
for (i = 0; i <= j; ++i) for (i = 0; i <= j; ++i)
sum += fjac(i,j) * (qtf[i] / fnorm); sum += fjac(i,j) * (qtf[i] / fnorm);
/* Computing MAX */ /* Computing MAX */
gnorm = std::max(gnorm, ei_abs(sum / wa2[l])); gnorm = std::max(gnorm, ei_abs(sum / wa2[l]));
L150: }
;
} }
L170: L170:

View File

@ -121,7 +121,7 @@ L60:
/* and initialize the step bound delta. */ /* and initialize the step bound delta. */
wa3 = diag.cwise() * x; wa3 = diag.cwise() * x;
xnorm = wa3.stableNorm();; xnorm = wa3.stableNorm();
delta = factor * xnorm; delta = factor * xnorm;
if (delta == 0.) { if (delta == 0.) {
delta = factor; delta = factor;

View File

@ -7,6 +7,7 @@ int ei_lmstr(
int &njev, int &njev,
Matrix< Scalar, Dynamic, Dynamic > &fjac, Matrix< Scalar, Dynamic, Dynamic > &fjac,
VectorXi &ipvt, VectorXi &ipvt,
Matrix< Scalar, Dynamic, 1 > &qtf,
Matrix< Scalar, Dynamic, 1 > &diag, Matrix< Scalar, Dynamic, 1 > &diag,
int mode=1, int mode=1,
Scalar factor = 100., Scalar factor = 100.,
@ -18,25 +19,23 @@ int ei_lmstr(
) )
{ {
const int m = fvec.size(), n = x.size(); const int m = fvec.size(), n = x.size();
Matrix< Scalar, Dynamic, 1 > Matrix< Scalar, Dynamic, 1 > wa1(n), wa2(n), wa3(n), wa4(m);
qtf(n),
wa1(n), wa2(n), wa3(n),
wa4(m);
ipvt.resize(n); ipvt.resize(n);
fjac.resize(m, n); fjac.resize(m, n);
diag.resize(n); diag.resize(n);
qtf.resize(n);
/* Local variables */ /* Local variables */
int i, j, l; int i, j, l;
Scalar par, sum; Scalar par, sum;
int sing; int sing, iter;
int iter;
Scalar temp, temp1, temp2; Scalar temp, temp1, temp2;
int iflag; int iflag;
Scalar delta; Scalar delta;
Scalar ratio; Scalar ratio;
Scalar fnorm, gnorm, pnorm, xnorm, fnorm1, actred, dirder, prered; Scalar fnorm, gnorm;
Scalar pnorm, xnorm, fnorm1, actred, dirder, prered;
int info; int info;
/* Function Body */ /* Function Body */
@ -51,7 +50,6 @@ int ei_lmstr(
gtol < 0. || maxfev <= 0 || factor <= 0.) { gtol < 0. || maxfev <= 0 || factor <= 0.) {
goto L340; goto L340;
} }
if (mode == 2) if (mode == 2)
for (j = 0; j < n; ++j) for (j = 0; j < n; ++j)
if (diag[j] <= 0.) goto L300; if (diag[j] <= 0.) goto L300;
@ -64,7 +62,7 @@ int ei_lmstr(
if (iflag < 0) { if (iflag < 0) {
goto L340; goto L340;
} }
fnorm = fvec.stableNorm();; fnorm = fvec.stableNorm();
/* initialize levenberg-marquardt parameter and iteration counter. */ /* initialize levenberg-marquardt parameter and iteration counter. */
@ -176,19 +174,13 @@ L170:
} }
for (j = 0; j < n; ++j) { for (j = 0; j < n; ++j) {
l = ipvt[j]; l = ipvt[j];
if (wa2[l] == 0.) { if (wa2[l] != 0.) {
goto L190;
}
sum = 0.; sum = 0.;
for (i = 0; i < j; ++i) { for (i = 0; i <= j; ++i)
sum += fjac(i,j) * (qtf[i] / fnorm); sum += fjac(i,j) * (qtf[i] / fnorm);
/* L180: */
}
/* Computing MAX */ /* Computing MAX */
gnorm = std::max(gnorm, ei_abs(sum / wa2[l])); gnorm = std::max(gnorm, ei_abs(sum / wa2[l]));
L190: }
/* L200: */
;
} }
L210: L210:
@ -249,8 +241,8 @@ L240:
/* compute the scaled predicted reduction and */ /* compute the scaled predicted reduction and */
/* the scaled directional derivative. */ /* the scaled directional derivative. */
wa3.fill(0.);
for (j = 0; j < n; ++j) { for (j = 0; j < n; ++j) {
wa3[j] = 0.;
l = ipvt[j]; l = ipvt[j];
temp = wa1[l]; temp = wa1[l];
for (i = 0; i <= j; ++i) { for (i = 0; i <= j; ++i) {
@ -284,9 +276,8 @@ L240:
if (actred < 0.) { if (actred < 0.) {
temp = Scalar(.5) * dirder / (dirder + Scalar(.5) * actred); temp = Scalar(.5) * dirder / (dirder + Scalar(.5) * actred);
} }
if (Scalar(.1) * fnorm1 >= fnorm || temp < Scalar(.1)) { if (Scalar(.1) * fnorm1 >= fnorm || temp < Scalar(.1))
temp = Scalar(.1); temp = Scalar(.1);
}
/* Computing MIN */ /* Computing MIN */
delta = temp * std::min(delta, pnorm / Scalar(.1)); delta = temp * std::min(delta, pnorm / Scalar(.1));

View File

@ -10,7 +10,7 @@ int ei_lmstr1(
const int n = x.size(), m=fvec.size(); const int n = x.size(), m=fvec.size();
int info, nfev=0, njev=0; int info, nfev=0, njev=0;
Matrix< Scalar, Dynamic, Dynamic > fjac(m, n); Matrix< Scalar, Dynamic, Dynamic > fjac(m, n);
Matrix< Scalar, Dynamic, 1> diag; Matrix< Scalar, Dynamic, 1> diag, qtf;
/* check the input parameters for errors. */ /* check the input parameters for errors. */
if (n <= 0 || m < n || tol < 0.) { if (n <= 0 || m < n || tol < 0.) {
@ -22,7 +22,7 @@ int ei_lmstr1(
info = ei_lmstr<Functor,Scalar>( info = ei_lmstr<Functor,Scalar>(
x, fvec, x, fvec,
nfev, njev, nfev, njev,
fjac, ipvt, diag, fjac, ipvt, qtf, diag,
1, 1,
100., 100.,
(n+1)*100, (n+1)*100,

View File

@ -461,7 +461,7 @@ void testLmstr()
const int m=15, n=3; const int m=15, n=3;
int info, nfev=0, njev=0; int info, nfev=0, njev=0;
double fnorm; double fnorm;
VectorXd x(n), fvec(m), diag(n); VectorXd x(n), fvec(m), diag(n), qtf;
MatrixXd fjac; MatrixXd fjac;
VectorXi ipvt; VectorXi ipvt;
@ -469,7 +469,7 @@ void testLmstr()
x.setConstant(n, 1.); x.setConstant(n, 1.);
// do the computation // do the computation
info = ei_lmstr<lmstr_functor, double>(x, fvec, nfev, njev, fjac, ipvt, diag); info = ei_lmstr<lmstr_functor, double>(x, fvec, nfev, njev, fjac, ipvt, qtf, diag);
VectorXd wa(n); VectorXd wa(n);
// check return values // check return values