aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h
diff options
context:
space:
mode:
Diffstat (limited to 'unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h')
-rw-r--r--unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h65
1 files changed, 34 insertions, 31 deletions
diff --git a/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h b/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h
index 9e982a078..2cf96eb14 100644
--- a/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h
+++ b/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h
@@ -29,6 +29,7 @@
#define EIGEN_LEVENBERGMARQUARDT__H
/**
+ * \ingroup NonLinearOptimization_Module
* \brief Performs non linear optimization over a non-linear function,
* using a variant of the Levenberg Marquardt algorithm.
*
@@ -72,56 +73,58 @@ public:
Scalar epsfcn;
};
+ typedef Matrix< Scalar, Dynamic, 1 > FVectorType;
+ typedef Matrix< Scalar, Dynamic, Dynamic > JacobianType;
+
Status lmder1(
- Matrix< Scalar, Dynamic, 1 > &x,
+ FVectorType &x,
const Scalar tol = ei_sqrt(epsilon<Scalar>())
);
Status minimize(
- Matrix< Scalar, Dynamic, 1 > &x,
+ FVectorType &x,
const int mode=1
);
Status minimizeInit(
- Matrix< Scalar, Dynamic, 1 > &x,
+ FVectorType &x,
const int mode=1
);
Status minimizeOneStep(
- Matrix< Scalar, Dynamic, 1 > &x,
+ FVectorType &x,
const int mode=1
);
static Status lmdif1(
FunctorType &functor,
- Matrix< Scalar, Dynamic, 1 > &x,
+ FVectorType &x,
int *nfev,
const Scalar tol = ei_sqrt(epsilon<Scalar>())
);
Status lmstr1(
- Matrix< Scalar, Dynamic, 1 > &x,
+ FVectorType &x,
const Scalar tol = ei_sqrt(epsilon<Scalar>())
);
Status minimizeOptimumStorage(
- Matrix< Scalar, Dynamic, 1 > &x,
+ FVectorType &x,
const int mode=1
);
Status minimizeOptimumStorageInit(
- Matrix< Scalar, Dynamic, 1 > &x,
+ FVectorType &x,
const int mode=1
);
Status minimizeOptimumStorageOneStep(
- Matrix< Scalar, Dynamic, 1 > &x,
+ FVectorType &x,
const int mode=1
);
void resetParameters(void) { parameters = Parameters(); }
+
Parameters parameters;
- Matrix< Scalar, Dynamic, 1 > fvec;
- Matrix< Scalar, Dynamic, Dynamic > fjac;
+ FVectorType fvec, qtf, diag;
+ JacobianType fjac;
VectorXi ipvt;
- Matrix< Scalar, Dynamic, 1 > qtf;
- Matrix< Scalar, Dynamic, 1 > diag;
int nfev;
int njev;
int iter;
@@ -130,7 +133,7 @@ private:
FunctorType &functor;
int n;
int m;
- Matrix< Scalar, Dynamic, 1 > wa1, wa2, wa3, wa4;
+ FVectorType wa1, wa2, wa3, wa4;
Scalar par, sum;
Scalar temp, temp1, temp2;
@@ -142,7 +145,7 @@ private:
template<typename FunctorType, typename Scalar>
typename LevenbergMarquardt<FunctorType,Scalar>::Status
LevenbergMarquardt<FunctorType,Scalar>::lmder1(
- Matrix< Scalar, Dynamic, 1 > &x,
+ FVectorType &x,
const Scalar tol
)
{
@@ -165,7 +168,7 @@ LevenbergMarquardt<FunctorType,Scalar>::lmder1(
template<typename FunctorType, typename Scalar>
typename LevenbergMarquardt<FunctorType,Scalar>::Status
LevenbergMarquardt<FunctorType,Scalar>::minimize(
- Matrix< Scalar, Dynamic, 1 > &x,
+ FVectorType &x,
const int mode
)
{
@@ -178,7 +181,7 @@ LevenbergMarquardt<FunctorType,Scalar>::minimize(
template<typename FunctorType, typename Scalar>
typename LevenbergMarquardt<FunctorType,Scalar>::Status
LevenbergMarquardt<FunctorType,Scalar>::minimizeInit(
- Matrix< Scalar, Dynamic, 1 > &x,
+ FVectorType &x,
const int mode
)
{
@@ -228,7 +231,7 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeInit(
template<typename FunctorType, typename Scalar>
typename LevenbergMarquardt<FunctorType,Scalar>::Status
LevenbergMarquardt<FunctorType,Scalar>::minimizeOneStep(
- Matrix< Scalar, Dynamic, 1 > &x,
+ FVectorType &x,
const int mode
)
{
@@ -246,8 +249,9 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeOneStep(
/* compute the qr factorization of the jacobian. */
- ei_qrfac<Scalar>(m, n, fjac.data(), fjac.rows(), true, ipvt.data(), wa1.data(), wa2.data());
- ipvt.cwise()-=1; // qrfac() creates ipvt with fortran convetion (1->n), convert it to c (0->n-1)
+ wa2 = fjac.colwise().blueNorm();
+ ei_qrfac<Scalar>(m, n, fjac.data(), fjac.rows(), true, ipvt.data(), wa1.data());
+ ipvt.cwise()-=1; // qrfac() creates ipvt with fortran convention (1->n), convert it to c (0->n-1)
/* on the first iteration and if mode is 1, scale according */
/* to the norms of the columns of the initial jacobian. */
@@ -317,7 +321,7 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeOneStep(
/* determine the levenberg-marquardt parameter. */
- ei_lmpar<Scalar>(fjac, ipvt, diag, qtf, delta, par, wa1, wa2);
+ ei_lmpar<Scalar>(fjac, ipvt, diag, qtf, delta, par, wa1);
/* store the direction p and x + p. calculate the norm of p. */
@@ -424,14 +428,12 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeOneStep(
template<typename FunctorType, typename Scalar>
typename LevenbergMarquardt<FunctorType,Scalar>::Status
LevenbergMarquardt<FunctorType,Scalar>::lmstr1(
- Matrix< Scalar, Dynamic, 1 > &x,
+ FVectorType &x,
const Scalar tol
)
{
n = x.size();
m = functor.values();
- Matrix< Scalar, Dynamic, Dynamic > fjac(m, n);
- VectorXi ipvt;
/* check the input parameters for errors. */
if (n <= 0 || m < n || tol < 0.)
@@ -448,7 +450,7 @@ LevenbergMarquardt<FunctorType,Scalar>::lmstr1(
template<typename FunctorType, typename Scalar>
typename LevenbergMarquardt<FunctorType,Scalar>::Status
LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorageInit(
- Matrix< Scalar, Dynamic, 1 > &x,
+ FVectorType &x,
const int mode
)
{
@@ -499,7 +501,7 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorageInit(
template<typename FunctorType, typename Scalar>
typename LevenbergMarquardt<FunctorType,Scalar>::Status
LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorageOneStep(
- Matrix< Scalar, Dynamic, 1 > &x,
+ FVectorType &x,
const int mode
)
{
@@ -535,8 +537,9 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorageOneStep(
}
if (sing) {
ipvt.cwise()+=1;
- ei_qrfac<Scalar>(n, n, fjac.data(), fjac.rows(), true, ipvt.data(), wa1.data(), wa2.data());
- ipvt.cwise()-=1; // qrfac() creates ipvt with fortran convetion (1->n), convert it to c (0->n-1)
+ wa2 = fjac.colwise().blueNorm();
+ ei_qrfac<Scalar>(n, n, fjac.data(), fjac.rows(), true, ipvt.data(), wa1.data());
+ ipvt.cwise()-=1; // qrfac() creates ipvt with fortran convention (1->n), convert it to c (0->n-1)
for (j = 0; j < n; ++j) {
if (fjac(j,j) != 0.) {
sum = 0.;
@@ -601,7 +604,7 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorageOneStep(
/* determine the levenberg-marquardt parameter. */
- ei_lmpar<Scalar>(fjac, ipvt, diag, qtf, delta, par, wa1, wa2);
+ ei_lmpar<Scalar>(fjac, ipvt, diag, qtf, delta, par, wa1);
/* store the direction p and x + p. calculate the norm of p. */
@@ -708,7 +711,7 @@ LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorageOneStep(
template<typename FunctorType, typename Scalar>
typename LevenbergMarquardt<FunctorType,Scalar>::Status
LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorage(
- Matrix< Scalar, Dynamic, 1 > &x,
+ FVectorType &x,
const int mode
)
{
@@ -722,7 +725,7 @@ template<typename FunctorType, typename Scalar>
typename LevenbergMarquardt<FunctorType,Scalar>::Status
LevenbergMarquardt<FunctorType,Scalar>::lmdif1(
FunctorType &functor,
- Matrix< Scalar, Dynamic, 1 > &x,
+ FVectorType &x,
int *nfev,
const Scalar tol
)