ei_lmpar : use a reference for the parameter

This commit is contained in:
Thomas Capricelli 2009-08-22 07:37:23 +02:00
parent b3f8d02df4
commit c5218c7d38
4 changed files with 16 additions and 21 deletions

View File

@ -215,13 +215,8 @@ L200:
/* determine the levenberg-marquardt parameter. */ /* determine the levenberg-marquardt parameter. */
ipvt.cwise()+=1; // lmpar() expects the fortran convention (as qrfac provides) ipvt.cwise()+=1; // lmpar() expects the fortran convention (as qrfac provides)
#if 1
ei_lmpar<Scalar>(n, fjac.data(), ldfjac, ipvt.data(), diag.data(), qtf.data(), delta, ei_lmpar<Scalar>(n, fjac.data(), ldfjac, ipvt.data(), diag.data(), qtf.data(), delta,
&par, wa1.data(), wa2.data(), wa3.data(), wa4.data()); par, wa1.data(), wa2.data(), wa3.data(), wa4.data());
#else
lmpar(n, fjac.data(), ldfjac, ipvt.data(), diag.data(), qtf.data(), delta,
&par, wa1.data(), wa2.data(), wa3.data(), wa4.data());
#endif
ipvt.cwise()-=1; ipvt.cwise()-=1;
/* store the direction p and x + p. calculate the norm of p. */ /* store the direction p and x + p. calculate the norm of p. */

View File

@ -219,7 +219,7 @@ L200:
ipvt.cwise()+=1; // lmpar() expects the fortran convention (as qrfac provides) ipvt.cwise()+=1; // lmpar() expects the fortran convention (as qrfac provides)
ei_lmpar<Scalar>(n, fjac.data(), ldfjac, ipvt.data(), diag.data(), qtf.data(), delta, ei_lmpar<Scalar>(n, fjac.data(), ldfjac, ipvt.data(), diag.data(), qtf.data(), delta,
&par, wa1.data(), wa2.data(), wa3.data(), wa4.data()); par, wa1.data(), wa2.data(), wa3.data(), wa4.data());
ipvt.cwise()-=1; ipvt.cwise()-=1;
/* store the direction p and x + p. calculate the norm of p. */ /* store the direction p and x + p. calculate the norm of p. */

View File

@ -2,7 +2,7 @@
template <typename Scalar> template <typename Scalar>
void ei_lmpar(int n, Scalar *r__, int ldr, void ei_lmpar(int n, Scalar *r__, int ldr,
const int *ipvt, const Scalar *diag, const Scalar *qtb, Scalar delta, const int *ipvt, const Scalar *diag, const Scalar *qtb, Scalar delta,
Scalar *par, Scalar *x, Scalar *sdiag, Scalar *wa1, Scalar &par, Scalar *x, Scalar *sdiag, Scalar *wa1,
Scalar *wa2) Scalar *wa2)
{ {
/* System generated locals */ /* System generated locals */
@ -142,10 +142,10 @@ L120:
/* if the input par lies outside of the interval (parl,paru), */ /* if the input par lies outside of the interval (parl,paru), */
/* set par to the closer endpoint. */ /* set par to the closer endpoint. */
*par = std::max(*par,parl); par = std::max(par,parl);
*par = std::min(*par,paru); par = std::min(par,paru);
if (*par == 0.) { if (par == 0.) {
*par = gnorm / dxnorm; par = gnorm / dxnorm;
} }
/* beginning of an iteration. */ /* beginning of an iteration. */
@ -155,12 +155,12 @@ L150:
/* evaluate the function at the current value of par. */ /* evaluate the function at the current value of par. */
if (*par == 0.) { if (par == 0.) {
/* Computing MAX */ /* Computing MAX */
d__1 = dwarf, d__2 = Scalar(.001) * paru; d__1 = dwarf, d__2 = Scalar(.001) * paru;
*par = std::max(d__1,d__2); par = std::max(d__1,d__2);
} }
temp = ei_sqrt(*par); temp = ei_sqrt(par);
for (j = 1; j <= n; ++j) { for (j = 1; j <= n; ++j) {
wa1[j] = temp * diag[j]; wa1[j] = temp * diag[j];
/* L160: */ /* L160: */
@ -211,17 +211,17 @@ L200:
/* depending on the sign of the function, update parl or paru. */ /* depending on the sign of the function, update parl or paru. */
if (fp > 0.) { if (fp > 0.) {
parl = std::max(parl,*par); parl = std::max(parl,par);
} }
if (fp < 0.) { if (fp < 0.) {
paru = std::min(paru,*par); paru = std::min(paru,par);
} }
/* compute an improved estimate for par. */ /* compute an improved estimate for par. */
/* Computing MAX */ /* Computing MAX */
d__1 = parl, d__2 = *par + parc; d__1 = parl, d__2 = par + parc;
*par = std::max(d__1,d__2); par = std::max(d__1,d__2);
/* end of an iteration. */ /* end of an iteration. */
@ -231,7 +231,7 @@ L220:
/* termination. */ /* termination. */
if (iter == 0) { if (iter == 0) {
*par = 0.; par = 0.;
} }
return; return;

View File

@ -242,7 +242,7 @@ L240:
/* determine the levenberg-marquardt parameter. */ /* determine the levenberg-marquardt parameter. */
ipvt.cwise()+=1; // lmpar() expects the fortran convention (as qrfac provides) ipvt.cwise()+=1; // lmpar() expects the fortran convention (as qrfac provides)
ei_lmpar<Scalar>(n, fjac.data(), ldfjac, ipvt.data(), diag.data(), qtf.data(), delta, &par, ei_lmpar<Scalar>(n, fjac.data(), ldfjac, ipvt.data(), diag.data(), qtf.data(), delta, par,
wa1.data(), wa2.data(), wa3.data(), wa4.data()); wa1.data(), wa2.data(), wa3.data(), wa4.data());
ipvt.cwise()-=1; ipvt.cwise()-=1;