This commit is contained in:
Hauke Heibel 2010-02-21 15:25:28 +01:00
commit f079f52b58
5 changed files with 70 additions and 142 deletions

View File

@ -322,7 +322,7 @@ template<typename Derived>
inline const LDLT<typename MatrixBase<Derived>::PlainObject> inline const LDLT<typename MatrixBase<Derived>::PlainObject>
MatrixBase<Derived>::ldlt() const MatrixBase<Derived>::ldlt() const
{ {
return derived(); return LDLT<PlainObject>(derived());
} }
#endif // EIGEN_LDLT_H #endif // EIGEN_LDLT_H

View File

@ -251,6 +251,7 @@ template<typename _MatrixType> class FullPivLU
{ {
m_usePrescribedThreshold = true; m_usePrescribedThreshold = true;
m_prescribedThreshold = threshold; m_prescribedThreshold = threshold;
return *this;
} }
/** Allows to come back to the default behavior, letting Eigen use its default formula for /** Allows to come back to the default behavior, letting Eigen use its default formula for

View File

@ -57,7 +57,7 @@ class HybridNonLinearSolver
{ {
public: public:
HybridNonLinearSolver(FunctorType &_functor) HybridNonLinearSolver(FunctorType &_functor)
: functor(_functor) { nfev=njev=iter = 0; fnorm= 0.; } : functor(_functor) { nfev=njev=iter = 0; fnorm= 0.; useExternalScaling=false;}
struct Parameters { struct Parameters {
Parameters() Parameters()
@ -84,36 +84,18 @@ public:
const Scalar tol = ei_sqrt(NumTraits<Scalar>::epsilon()) const Scalar tol = ei_sqrt(NumTraits<Scalar>::epsilon())
); );
HybridNonLinearSolverSpace::Status solveInit( HybridNonLinearSolverSpace::Status solveInit(FVectorType &x);
FVectorType &x, HybridNonLinearSolverSpace::Status solveOneStep(FVectorType &x);
const int mode=1 HybridNonLinearSolverSpace::Status solve(FVectorType &x);
);
HybridNonLinearSolverSpace::Status solveOneStep(
FVectorType &x,
const int mode=1
);
HybridNonLinearSolverSpace::Status solve(
FVectorType &x,
const int mode=1
);
HybridNonLinearSolverSpace::Status hybrd1( HybridNonLinearSolverSpace::Status hybrd1(
FVectorType &x, FVectorType &x,
const Scalar tol = ei_sqrt(NumTraits<Scalar>::epsilon()) const Scalar tol = ei_sqrt(NumTraits<Scalar>::epsilon())
); );
HybridNonLinearSolverSpace::Status solveNumericalDiffInit( HybridNonLinearSolverSpace::Status solveNumericalDiffInit(FVectorType &x);
FVectorType &x, HybridNonLinearSolverSpace::Status solveNumericalDiffOneStep(FVectorType &x);
const int mode=1 HybridNonLinearSolverSpace::Status solveNumericalDiff(FVectorType &x);
);
HybridNonLinearSolverSpace::Status solveNumericalDiffOneStep(
FVectorType &x,
const int mode=1
);
HybridNonLinearSolverSpace::Status solveNumericalDiff(
FVectorType &x,
const int mode=1
);
void resetParameters(void) { parameters = Parameters(); } void resetParameters(void) { parameters = Parameters(); }
Parameters parameters; Parameters parameters;
@ -124,6 +106,7 @@ public:
int njev; int njev;
int iter; int iter;
Scalar fnorm; Scalar fnorm;
bool useExternalScaling;
private: private:
FunctorType &functor; FunctorType &functor;
int n; int n;
@ -160,18 +143,13 @@ HybridNonLinearSolver<FunctorType,Scalar>::hybrj1(
parameters.maxfev = 100*(n+1); parameters.maxfev = 100*(n+1);
parameters.xtol = tol; parameters.xtol = tol;
diag.setConstant(n, 1.); diag.setConstant(n, 1.);
return solve( useExternalScaling = true;
x, return solve(x);
2
);
} }
template<typename FunctorType, typename Scalar> template<typename FunctorType, typename Scalar>
HybridNonLinearSolverSpace::Status HybridNonLinearSolverSpace::Status
HybridNonLinearSolver<FunctorType,Scalar>::solveInit( HybridNonLinearSolver<FunctorType,Scalar>::solveInit(FVectorType &x)
FVectorType &x,
const int mode
)
{ {
n = x.size(); n = x.size();
@ -179,9 +157,9 @@ HybridNonLinearSolver<FunctorType,Scalar>::solveInit(
fvec.resize(n); fvec.resize(n);
qtf.resize(n); qtf.resize(n);
fjac.resize(n, n); fjac.resize(n, n);
if (mode != 2) if (!useExternalScaling)
diag.resize(n); diag.resize(n);
assert( (mode!=2 || diag.size()==n) || "When using mode==2, the caller must provide a valid 'diag'"); assert( (!useExternalScaling || diag.size()==n) || "When useExternalScaling is set, the caller must provide a valid 'diag'");
/* Function Body */ /* Function Body */
nfev = 0; nfev = 0;
@ -190,7 +168,7 @@ HybridNonLinearSolver<FunctorType,Scalar>::solveInit(
/* check the input parameters for errors. */ /* check the input parameters for errors. */
if (n <= 0 || parameters.xtol < 0. || parameters.maxfev <= 0 || parameters.factor <= 0. ) if (n <= 0 || parameters.xtol < 0. || parameters.maxfev <= 0 || parameters.factor <= 0. )
return HybridNonLinearSolverSpace::ImproperInputParameters; return HybridNonLinearSolverSpace::ImproperInputParameters;
if (mode == 2) if (useExternalScaling)
for (int j = 0; j < n; ++j) for (int j = 0; j < n; ++j)
if (diag[j] <= 0.) if (diag[j] <= 0.)
return HybridNonLinearSolverSpace::ImproperInputParameters; return HybridNonLinearSolverSpace::ImproperInputParameters;
@ -214,10 +192,7 @@ HybridNonLinearSolver<FunctorType,Scalar>::solveInit(
template<typename FunctorType, typename Scalar> template<typename FunctorType, typename Scalar>
HybridNonLinearSolverSpace::Status HybridNonLinearSolverSpace::Status
HybridNonLinearSolver<FunctorType,Scalar>::solveOneStep( HybridNonLinearSolver<FunctorType,Scalar>::solveOneStep(FVectorType &x)
FVectorType &x,
const int mode
)
{ {
int j; int j;
std::vector<PlanarRotation<Scalar> > v_givens(n), w_givens(n); std::vector<PlanarRotation<Scalar> > v_givens(n), w_givens(n);
@ -231,10 +206,10 @@ HybridNonLinearSolver<FunctorType,Scalar>::solveOneStep(
wa2 = fjac.colwise().blueNorm(); wa2 = fjac.colwise().blueNorm();
/* on the first iteration and if mode is 1, scale according */ /* on the first iteration and if external scaling is not used, scale according */
/* to the norms of the columns of the initial jacobian. */ /* to the norms of the columns of the initial jacobian. */
if (iter == 1) { if (iter == 1) {
if (mode != 2) if (!useExternalScaling)
for (j = 0; j < n; ++j) for (j = 0; j < n; ++j)
diag[j] = (wa2[j]==0.) ? 1. : wa2[j]; diag[j] = (wa2[j]==0.) ? 1. : wa2[j];
@ -260,7 +235,7 @@ HybridNonLinearSolver<FunctorType,Scalar>::solveOneStep(
qtf = fjac.transpose() * fvec; qtf = fjac.transpose() * fvec;
/* rescale if necessary. */ /* rescale if necessary. */
if (mode != 2) if (!useExternalScaling)
diag = diag.cwiseMax(wa2); diag = diag.cwiseMax(wa2);
while (true) { while (true) {
@ -372,14 +347,11 @@ HybridNonLinearSolver<FunctorType,Scalar>::solveOneStep(
template<typename FunctorType, typename Scalar> template<typename FunctorType, typename Scalar>
HybridNonLinearSolverSpace::Status HybridNonLinearSolverSpace::Status
HybridNonLinearSolver<FunctorType,Scalar>::solve( HybridNonLinearSolver<FunctorType,Scalar>::solve(FVectorType &x)
FVectorType &x,
const int mode
)
{ {
HybridNonLinearSolverSpace::Status status = solveInit(x, mode); HybridNonLinearSolverSpace::Status status = solveInit(x);
while (status==HybridNonLinearSolverSpace::Running) while (status==HybridNonLinearSolverSpace::Running)
status = solveOneStep(x, mode); status = solveOneStep(x);
return status; return status;
} }
@ -403,18 +375,13 @@ HybridNonLinearSolver<FunctorType,Scalar>::hybrd1(
parameters.xtol = tol; parameters.xtol = tol;
diag.setConstant(n, 1.); diag.setConstant(n, 1.);
return solveNumericalDiff( useExternalScaling = true;
x, return solveNumericalDiff(x);
2
);
} }
template<typename FunctorType, typename Scalar> template<typename FunctorType, typename Scalar>
HybridNonLinearSolverSpace::Status HybridNonLinearSolverSpace::Status
HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiffInit( HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiffInit(FVectorType &x)
FVectorType &x,
const int mode
)
{ {
n = x.size(); n = x.size();
@ -425,10 +392,9 @@ HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiffInit(
qtf.resize(n); qtf.resize(n);
fjac.resize(n, n); fjac.resize(n, n);
fvec.resize(n); fvec.resize(n);
if (mode != 2) if (!useExternalScaling)
diag.resize(n); diag.resize(n);
assert( (mode!=2 || diag.size()==n) || "When using mode==2, the caller must provide a valid 'diag'"); assert( (!useExternalScaling || diag.size()==n) || "When useExternalScaling is set, the caller must provide a valid 'diag'");
/* Function Body */ /* Function Body */
nfev = 0; nfev = 0;
@ -437,7 +403,7 @@ HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiffInit(
/* check the input parameters for errors. */ /* check the input parameters for errors. */
if (n <= 0 || parameters.xtol < 0. || parameters.maxfev <= 0 || parameters.nb_of_subdiagonals< 0 || parameters.nb_of_superdiagonals< 0 || parameters.factor <= 0. ) if (n <= 0 || parameters.xtol < 0. || parameters.maxfev <= 0 || parameters.nb_of_subdiagonals< 0 || parameters.nb_of_superdiagonals< 0 || parameters.factor <= 0. )
return HybridNonLinearSolverSpace::ImproperInputParameters; return HybridNonLinearSolverSpace::ImproperInputParameters;
if (mode == 2) if (useExternalScaling)
for (int j = 0; j < n; ++j) for (int j = 0; j < n; ++j)
if (diag[j] <= 0.) if (diag[j] <= 0.)
return HybridNonLinearSolverSpace::ImproperInputParameters; return HybridNonLinearSolverSpace::ImproperInputParameters;
@ -461,10 +427,7 @@ HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiffInit(
template<typename FunctorType, typename Scalar> template<typename FunctorType, typename Scalar>
HybridNonLinearSolverSpace::Status HybridNonLinearSolverSpace::Status
HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiffOneStep( HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiffOneStep(FVectorType &x)
FVectorType &x,
const int mode
)
{ {
int j; int j;
std::vector<PlanarRotation<Scalar> > v_givens(n), w_givens(n); std::vector<PlanarRotation<Scalar> > v_givens(n), w_givens(n);
@ -480,10 +443,10 @@ HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiffOneStep(
wa2 = fjac.colwise().blueNorm(); wa2 = fjac.colwise().blueNorm();
/* on the first iteration and if mode is 1, scale according */ /* on the first iteration and if external scaling is not used, scale according */
/* to the norms of the columns of the initial jacobian. */ /* to the norms of the columns of the initial jacobian. */
if (iter == 1) { if (iter == 1) {
if (mode != 2) if (!useExternalScaling)
for (j = 0; j < n; ++j) for (j = 0; j < n; ++j)
diag[j] = (wa2[j]==0.) ? 1. : wa2[j]; diag[j] = (wa2[j]==0.) ? 1. : wa2[j];
@ -509,7 +472,7 @@ HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiffOneStep(
qtf = fjac.transpose() * fvec; qtf = fjac.transpose() * fvec;
/* rescale if necessary. */ /* rescale if necessary. */
if (mode != 2) if (!useExternalScaling)
diag = diag.cwiseMax(wa2); diag = diag.cwiseMax(wa2);
while (true) { while (true) {
@ -621,14 +584,11 @@ HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiffOneStep(
template<typename FunctorType, typename Scalar> template<typename FunctorType, typename Scalar>
HybridNonLinearSolverSpace::Status HybridNonLinearSolverSpace::Status
HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiff( HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiff(FVectorType &x)
FVectorType &x,
const int mode
)
{ {
HybridNonLinearSolverSpace::Status status = solveNumericalDiffInit(x, mode); HybridNonLinearSolverSpace::Status status = solveNumericalDiffInit(x);
while (status==HybridNonLinearSolverSpace::Running) while (status==HybridNonLinearSolverSpace::Running)
status = solveNumericalDiffOneStep(x, mode); status = solveNumericalDiffOneStep(x);
return status; return status;
} }

View File

@ -61,7 +61,7 @@ class LevenbergMarquardt
{ {
public: public:
LevenbergMarquardt(FunctorType &_functor) LevenbergMarquardt(FunctorType &_functor)
: functor(_functor) { nfev = njev = iter = 0; fnorm=gnorm = 0.; } : functor(_functor) { nfev = njev = iter = 0; fnorm = gnorm = 0.; useExternalScaling=false; }
struct Parameters { struct Parameters {
Parameters() Parameters()
@ -87,18 +87,9 @@ public:
const Scalar tol = ei_sqrt(NumTraits<Scalar>::epsilon()) const Scalar tol = ei_sqrt(NumTraits<Scalar>::epsilon())
); );
LevenbergMarquardtSpace::Status minimize( LevenbergMarquardtSpace::Status minimize(FVectorType &x);
FVectorType &x, LevenbergMarquardtSpace::Status minimizeInit(FVectorType &x);
const int mode=1 LevenbergMarquardtSpace::Status minimizeOneStep(FVectorType &x);
);
LevenbergMarquardtSpace::Status minimizeInit(
FVectorType &x,
const int mode=1
);
LevenbergMarquardtSpace::Status minimizeOneStep(
FVectorType &x,
const int mode=1
);
static LevenbergMarquardtSpace::Status lmdif1( static LevenbergMarquardtSpace::Status lmdif1(
FunctorType &functor, FunctorType &functor,
@ -112,18 +103,9 @@ public:
const Scalar tol = ei_sqrt(NumTraits<Scalar>::epsilon()) const Scalar tol = ei_sqrt(NumTraits<Scalar>::epsilon())
); );
LevenbergMarquardtSpace::Status minimizeOptimumStorage( LevenbergMarquardtSpace::Status minimizeOptimumStorage(FVectorType &x);
FVectorType &x, LevenbergMarquardtSpace::Status minimizeOptimumStorageInit(FVectorType &x);
const int mode=1 LevenbergMarquardtSpace::Status minimizeOptimumStorageOneStep(FVectorType &x);
);
LevenbergMarquardtSpace::Status minimizeOptimumStorageInit(
FVectorType &x,
const int mode=1
);
LevenbergMarquardtSpace::Status minimizeOptimumStorageOneStep(
FVectorType &x,
const int mode=1
);
void resetParameters(void) { parameters = Parameters(); } void resetParameters(void) { parameters = Parameters(); }
@ -135,6 +117,7 @@ public:
int njev; int njev;
int iter; int iter;
Scalar fnorm, gnorm; Scalar fnorm, gnorm;
bool useExternalScaling;
Scalar lm_param(void) { return par; } Scalar lm_param(void) { return par; }
private: private:
@ -175,24 +158,18 @@ LevenbergMarquardt<FunctorType,Scalar>::lmder1(
template<typename FunctorType, typename Scalar> template<typename FunctorType, typename Scalar>
LevenbergMarquardtSpace::Status LevenbergMarquardtSpace::Status
LevenbergMarquardt<FunctorType,Scalar>::minimize( LevenbergMarquardt<FunctorType,Scalar>::minimize(FVectorType &x)
FVectorType &x,
const int mode
)
{ {
LevenbergMarquardtSpace::Status status = minimizeInit(x, mode); LevenbergMarquardtSpace::Status status = minimizeInit(x);
do { do {
status = minimizeOneStep(x, mode); status = minimizeOneStep(x);
} while (status==LevenbergMarquardtSpace::Running); } while (status==LevenbergMarquardtSpace::Running);
return status; return status;
} }
template<typename FunctorType, typename Scalar> template<typename FunctorType, typename Scalar>
LevenbergMarquardtSpace::Status LevenbergMarquardtSpace::Status
LevenbergMarquardt<FunctorType,Scalar>::minimizeInit( LevenbergMarquardt<FunctorType,Scalar>::minimizeInit(FVectorType &x)
FVectorType &x,
const int mode
)
{ {
n = x.size(); n = x.size();
m = functor.values(); m = functor.values();
@ -201,9 +178,9 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeInit(
wa4.resize(m); wa4.resize(m);
fvec.resize(m); fvec.resize(m);
fjac.resize(m, n); fjac.resize(m, n);
if (mode != 2) if (!useExternalScaling)
diag.resize(n); diag.resize(n);
assert( (mode!=2 || diag.size()==n) || "When using mode==2, the caller must provide a valid 'diag'"); assert( (!useExternalScaling || diag.size()==n) || "When useExternalScaling is set, the caller must provide a valid 'diag'");
qtf.resize(n); qtf.resize(n);
/* Function Body */ /* Function Body */
@ -214,7 +191,7 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeInit(
if (n <= 0 || m < n || parameters.ftol < 0. || parameters.xtol < 0. || parameters.gtol < 0. || parameters.maxfev <= 0 || parameters.factor <= 0.) if (n <= 0 || m < n || parameters.ftol < 0. || parameters.xtol < 0. || parameters.gtol < 0. || parameters.maxfev <= 0 || parameters.factor <= 0.)
return LevenbergMarquardtSpace::ImproperInputParameters; return LevenbergMarquardtSpace::ImproperInputParameters;
if (mode == 2) if (useExternalScaling)
for (int j = 0; j < n; ++j) for (int j = 0; j < n; ++j)
if (diag[j] <= 0.) if (diag[j] <= 0.)
return LevenbergMarquardtSpace::ImproperInputParameters; return LevenbergMarquardtSpace::ImproperInputParameters;
@ -235,10 +212,7 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeInit(
template<typename FunctorType, typename Scalar> template<typename FunctorType, typename Scalar>
LevenbergMarquardtSpace::Status LevenbergMarquardtSpace::Status
LevenbergMarquardt<FunctorType,Scalar>::minimizeOneStep( LevenbergMarquardt<FunctorType,Scalar>::minimizeOneStep(FVectorType &x)
FVectorType &x,
const int mode
)
{ {
int j; int j;
@ -257,10 +231,10 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeOneStep(
fjac = qrfac.matrixQR(); fjac = qrfac.matrixQR();
permutation = qrfac.colsPermutation(); permutation = qrfac.colsPermutation();
/* on the first iteration and if mode is 1, scale according */ /* on the first iteration and if external scaling is not used, scale according */
/* to the norms of the columns of the initial jacobian. */ /* to the norms of the columns of the initial jacobian. */
if (iter == 1) { if (iter == 1) {
if (mode != 2) if (!useExternalScaling)
for (j = 0; j < n; ++j) for (j = 0; j < n; ++j)
diag[j] = (wa2[j]==0.)? 1. : wa2[j]; diag[j] = (wa2[j]==0.)? 1. : wa2[j];
@ -290,7 +264,7 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeOneStep(
return LevenbergMarquardtSpace::CosinusTooSmall; return LevenbergMarquardtSpace::CosinusTooSmall;
/* rescale if necessary. */ /* rescale if necessary. */
if (mode != 2) if (!useExternalScaling)
diag = diag.cwiseMax(wa2); diag = diag.cwiseMax(wa2);
do { do {
@ -406,10 +380,7 @@ LevenbergMarquardt<FunctorType,Scalar>::lmstr1(
template<typename FunctorType, typename Scalar> template<typename FunctorType, typename Scalar>
LevenbergMarquardtSpace::Status LevenbergMarquardtSpace::Status
LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorageInit( LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorageInit(FVectorType &x)
FVectorType &x,
const int mode
)
{ {
n = x.size(); n = x.size();
m = functor.values(); m = functor.values();
@ -423,9 +394,9 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorageInit(
// The purpose it to only use a nxn matrix, instead of mxn here, so // The purpose it to only use a nxn matrix, instead of mxn here, so
// that we can handle cases where m>>n : // that we can handle cases where m>>n :
fjac.resize(n, n); fjac.resize(n, n);
if (mode != 2) if (!useExternalScaling)
diag.resize(n); diag.resize(n);
assert( (mode!=2 || diag.size()==n) || "When using mode==2, the caller must provide a valid 'diag'"); assert( (!useExternalScaling || diag.size()==n) || "When useExternalScaling is set, the caller must provide a valid 'diag'");
qtf.resize(n); qtf.resize(n);
/* Function Body */ /* Function Body */
@ -436,7 +407,7 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorageInit(
if (n <= 0 || m < n || parameters.ftol < 0. || parameters.xtol < 0. || parameters.gtol < 0. || parameters.maxfev <= 0 || parameters.factor <= 0.) if (n <= 0 || m < n || parameters.ftol < 0. || parameters.xtol < 0. || parameters.gtol < 0. || parameters.maxfev <= 0 || parameters.factor <= 0.)
return LevenbergMarquardtSpace::ImproperInputParameters; return LevenbergMarquardtSpace::ImproperInputParameters;
if (mode == 2) if (useExternalScaling)
for (int j = 0; j < n; ++j) for (int j = 0; j < n; ++j)
if (diag[j] <= 0.) if (diag[j] <= 0.)
return LevenbergMarquardtSpace::ImproperInputParameters; return LevenbergMarquardtSpace::ImproperInputParameters;
@ -458,10 +429,7 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorageInit(
template<typename FunctorType, typename Scalar> template<typename FunctorType, typename Scalar>
LevenbergMarquardtSpace::Status LevenbergMarquardtSpace::Status
LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorageOneStep( LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorageOneStep(FVectorType &x)
FVectorType &x,
const int mode
)
{ {
int i, j; int i, j;
bool sing; bool sing;
@ -514,10 +482,10 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorageOneStep(
} }
} }
/* on the first iteration and if mode is 1, scale according */ /* on the first iteration and if external scaling is not used, scale according */
/* to the norms of the columns of the initial jacobian. */ /* to the norms of the columns of the initial jacobian. */
if (iter == 1) { if (iter == 1) {
if (mode != 2) if (!useExternalScaling)
for (j = 0; j < n; ++j) for (j = 0; j < n; ++j)
diag[j] = (wa2[j]==0.)? 1. : wa2[j]; diag[j] = (wa2[j]==0.)? 1. : wa2[j];
@ -541,7 +509,7 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorageOneStep(
return LevenbergMarquardtSpace::CosinusTooSmall; return LevenbergMarquardtSpace::CosinusTooSmall;
/* rescale if necessary. */ /* rescale if necessary. */
if (mode != 2) if (!useExternalScaling)
diag = diag.cwiseMax(wa2); diag = diag.cwiseMax(wa2);
do { do {
@ -635,14 +603,11 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorageOneStep(
template<typename FunctorType, typename Scalar> template<typename FunctorType, typename Scalar>
LevenbergMarquardtSpace::Status LevenbergMarquardtSpace::Status
LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorage( LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorage(FVectorType &x)
FVectorType &x,
const int mode
)
{ {
LevenbergMarquardtSpace::Status status = minimizeOptimumStorageInit(x, mode); LevenbergMarquardtSpace::Status status = minimizeOptimumStorageInit(x);
do { do {
status = minimizeOptimumStorageOneStep(x, mode); status = minimizeOptimumStorageOneStep(x);
} while (status==LevenbergMarquardtSpace::Running); } while (status==LevenbergMarquardtSpace::Running);
return status; return status;
} }

View File

@ -317,7 +317,8 @@ void testHybrj()
hybrj_functor functor; hybrj_functor functor;
HybridNonLinearSolver<hybrj_functor> solver(functor); HybridNonLinearSolver<hybrj_functor> solver(functor);
solver.diag.setConstant(n, 1.); solver.diag.setConstant(n, 1.);
info = solver.solve(x, 2); solver.useExternalScaling = true;
info = solver.solve(x);
// check return value // check return value
VERIFY( 1 == info); VERIFY( 1 == info);
@ -401,7 +402,8 @@ void testHybrd()
solver.parameters.nb_of_subdiagonals = 1; solver.parameters.nb_of_subdiagonals = 1;
solver.parameters.nb_of_superdiagonals = 1; solver.parameters.nb_of_superdiagonals = 1;
solver.diag.setConstant(n, 1.); solver.diag.setConstant(n, 1.);
info = solver.solveNumericalDiff(x, 2); solver.useExternalScaling = true;
info = solver.solveNumericalDiff(x);
// check return value // check return value
VERIFY( 1 == info); VERIFY( 1 == info);