mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-30 07:44:10 +08:00
move more stuff into Parameters
This commit is contained in:
parent
a2abb4afb6
commit
bbd44ef0ad
@ -21,10 +21,16 @@ public:
|
|||||||
Parameters()
|
Parameters()
|
||||||
: factor(Scalar(100.))
|
: factor(Scalar(100.))
|
||||||
, maxfev(1000)
|
, maxfev(1000)
|
||||||
, xtol(ei_sqrt(epsilon<Scalar>())) {}
|
, xtol(ei_sqrt(epsilon<Scalar>()))
|
||||||
|
, nb_of_subdiagonals(-1)
|
||||||
|
, nb_of_superdiagonals(-1)
|
||||||
|
, epsfcn (Scalar(0.)) {}
|
||||||
Scalar factor;
|
Scalar factor;
|
||||||
int maxfev; // maximum number of function evaluation
|
int maxfev; // maximum number of function evaluation
|
||||||
Scalar xtol;
|
Scalar xtol;
|
||||||
|
int nb_of_subdiagonals;
|
||||||
|
int nb_of_superdiagonals;
|
||||||
|
Scalar epsfcn;
|
||||||
};
|
};
|
||||||
|
|
||||||
Status solve(
|
Status solve(
|
||||||
@ -44,10 +50,7 @@ public:
|
|||||||
Status solveNumericalDiff(
|
Status solveNumericalDiff(
|
||||||
Matrix< Scalar, Dynamic, 1 > &x,
|
Matrix< Scalar, Dynamic, 1 > &x,
|
||||||
const Parameters ¶meters,
|
const Parameters ¶meters,
|
||||||
const int mode=1,
|
const int mode=1
|
||||||
int nb_of_subdiagonals = -1,
|
|
||||||
int nb_of_superdiagonals = -1,
|
|
||||||
const Scalar epsfcn = Scalar(0.)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Matrix< Scalar, Dynamic, 1 > fvec;
|
Matrix< Scalar, Dynamic, 1 > fvec;
|
||||||
@ -406,16 +409,15 @@ typename HybridNonLinearSolver<FunctorType,Scalar>::Status
|
|||||||
HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiff(
|
HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiff(
|
||||||
Matrix< Scalar, Dynamic, 1 > &x,
|
Matrix< Scalar, Dynamic, 1 > &x,
|
||||||
const Parameters ¶meters,
|
const Parameters ¶meters,
|
||||||
const int mode,
|
const int mode
|
||||||
int nb_of_subdiagonals,
|
|
||||||
int nb_of_superdiagonals,
|
|
||||||
const Scalar epsfcn
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
n = x.size();
|
n = x.size();
|
||||||
|
|
||||||
if (nb_of_subdiagonals<0) nb_of_subdiagonals = n-1;
|
int nsub = parameters.nb_of_subdiagonals;
|
||||||
if (nb_of_superdiagonals<0) nb_of_superdiagonals = n-1;
|
int nsup = parameters.nb_of_superdiagonals;
|
||||||
|
if (nsub<0) nsub= n-1;
|
||||||
|
if (nsup<0) nsup= n-1;
|
||||||
|
|
||||||
wa1.resize(n); wa2.resize(n); wa3.resize(n); wa4.resize(n);
|
wa1.resize(n); wa2.resize(n); wa3.resize(n); wa4.resize(n);
|
||||||
qtf.resize(n);
|
qtf.resize(n);
|
||||||
@ -432,7 +434,7 @@ HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiff(
|
|||||||
|
|
||||||
/* check the input parameters for errors. */
|
/* check the input parameters for errors. */
|
||||||
|
|
||||||
if (n <= 0 || parameters.xtol < 0. || parameters.maxfev <= 0 || nb_of_subdiagonals < 0 || nb_of_superdiagonals < 0 || parameters.factor <= 0. )
|
if (n <= 0 || parameters.xtol < 0. || parameters.maxfev <= 0 || nsub< 0 || nsup< 0 || parameters.factor <= 0. )
|
||||||
return ImproperInputParameters;
|
return ImproperInputParameters;
|
||||||
if (mode == 2)
|
if (mode == 2)
|
||||||
for (int j = 0; j < n; ++j)
|
for (int j = 0; j < n; ++j)
|
||||||
@ -463,9 +465,9 @@ HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiff(
|
|||||||
|
|
||||||
/* calculate the jacobian matrix. */
|
/* calculate the jacobian matrix. */
|
||||||
|
|
||||||
if (ei_fdjac1(functor, x, fvec, fjac, nb_of_subdiagonals, nb_of_superdiagonals, epsfcn) <0)
|
if (ei_fdjac1(functor, x, fvec, fjac, nsub, nsup, parameters.epsfcn) <0)
|
||||||
return UserAksed;
|
return UserAksed;
|
||||||
nfev += std::min(nb_of_subdiagonals + nb_of_superdiagonals + 1, n);
|
nfev += std::min(nsub+ nsup+ 1, n);
|
||||||
|
|
||||||
/* compute the qr factorization of the jacobian. */
|
/* compute the qr factorization of the jacobian. */
|
||||||
|
|
||||||
|
@ -26,12 +26,14 @@ public:
|
|||||||
, maxfev(400)
|
, maxfev(400)
|
||||||
, ftol(ei_sqrt(epsilon<Scalar>()))
|
, ftol(ei_sqrt(epsilon<Scalar>()))
|
||||||
, xtol(ei_sqrt(epsilon<Scalar>()))
|
, xtol(ei_sqrt(epsilon<Scalar>()))
|
||||||
, gtol(Scalar(0.)) { }
|
, gtol(Scalar(0.))
|
||||||
|
, epsfcn (Scalar(0.)) {}
|
||||||
Scalar factor;
|
Scalar factor;
|
||||||
int maxfev; // maximum number of function evaluation
|
int maxfev; // maximum number of function evaluation
|
||||||
Scalar ftol;
|
Scalar ftol;
|
||||||
Scalar xtol;
|
Scalar xtol;
|
||||||
Scalar gtol;
|
Scalar gtol;
|
||||||
|
Scalar epsfcn;
|
||||||
};
|
};
|
||||||
|
|
||||||
Status minimize(
|
Status minimize(
|
||||||
@ -53,8 +55,7 @@ public:
|
|||||||
Status minimizeNumericalDiff(
|
Status minimizeNumericalDiff(
|
||||||
Matrix< Scalar, Dynamic, 1 > &x,
|
Matrix< Scalar, Dynamic, 1 > &x,
|
||||||
const Parameters ¶meters,
|
const Parameters ¶meters,
|
||||||
const int mode=1,
|
const int mode=1
|
||||||
const Scalar epsfcn = Scalar(0.)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Status minimizeOptimumStorage(
|
Status minimizeOptimumStorage(
|
||||||
@ -387,8 +388,7 @@ typename LevenbergMarquardt<FunctorType,Scalar>::Status
|
|||||||
LevenbergMarquardt<FunctorType,Scalar>::minimizeNumericalDiff(
|
LevenbergMarquardt<FunctorType,Scalar>::minimizeNumericalDiff(
|
||||||
Matrix< Scalar, Dynamic, 1 > &x,
|
Matrix< Scalar, Dynamic, 1 > &x,
|
||||||
const Parameters ¶meters,
|
const Parameters ¶meters,
|
||||||
const int mode,
|
const int mode
|
||||||
const Scalar epsfcn
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
n = x.size();
|
n = x.size();
|
||||||
@ -436,7 +436,7 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeNumericalDiff(
|
|||||||
|
|
||||||
/* calculate the jacobian matrix. */
|
/* calculate the jacobian matrix. */
|
||||||
|
|
||||||
if ( ei_fdjac2(functor, x, fvec, fjac, epsfcn) < 0)
|
if ( ei_fdjac2(functor, x, fvec, fjac, parameters.epsfcn) < 0)
|
||||||
return UserAsked;
|
return UserAsked;
|
||||||
nfev += n;
|
nfev += n;
|
||||||
|
|
||||||
|
@ -373,21 +373,20 @@ void testHybrd1()
|
|||||||
void testHybrd()
|
void testHybrd()
|
||||||
{
|
{
|
||||||
const int n=9;
|
const int n=9;
|
||||||
int info, ml, mu;
|
int info;
|
||||||
VectorXd x;
|
VectorXd x;
|
||||||
|
|
||||||
/* the following starting values provide a rough fit. */
|
/* the following starting values provide a rough fit. */
|
||||||
x.setConstant(n, -1.);
|
x.setConstant(n, -1.);
|
||||||
|
|
||||||
ml = 1;
|
|
||||||
mu = 1;
|
|
||||||
|
|
||||||
// do the computation
|
// do the computation
|
||||||
hybrd_functor functor;
|
hybrd_functor functor;
|
||||||
HybridNonLinearSolver<hybrd_functor> solver(functor);
|
HybridNonLinearSolver<hybrd_functor> solver(functor);
|
||||||
HybridNonLinearSolver<hybrd_functor>::Parameters parameters;
|
HybridNonLinearSolver<hybrd_functor>::Parameters parameters;
|
||||||
|
parameters.nb_of_subdiagonals = 1;
|
||||||
|
parameters.nb_of_superdiagonals = 1;
|
||||||
solver.diag.setConstant(n, 1.);
|
solver.diag.setConstant(n, 1.);
|
||||||
info = solver.solveNumericalDiff(x, parameters, 2, ml, mu);
|
info = solver.solveNumericalDiff(x, parameters, 2);
|
||||||
|
|
||||||
// check return value
|
// check return value
|
||||||
VERIFY( 1 == info);
|
VERIFY( 1 == info);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user