19#ifndef EIGEN_LEVENBERGMARQUARDT_H
20#define EIGEN_LEVENBERGMARQUARDT_H
24namespace LevenbergMarquardtSpace {
41template <
typename _Scalar,
int NX=Dynamic,
int NY=Dynamic>
68template <
typename _Scalar,
typename _Index>
96template <
typename QRSolver,
typename VectorType>
98 typename VectorType::Scalar m_delta,
typename VectorType::Scalar &par,
109template<
typename _FunctorType>
116 typedef typename JacobianType::Scalar
Scalar;
123 : m_functor(functor),m_nfev(0),m_njev(0),m_fnorm(0.0),m_gnorm(0),
127 m_useExternalScaling=
false;
267 bool m_useExternalScaling;
271 bool m_isInitialized;
275template<
typename FunctorType>
281 m_isInitialized =
true;
286 status = minimizeOneStep(
x);
288 m_isInitialized =
true;
292template<
typename FunctorType>
297 m = m_functor.values();
299 m_wa1.resize(
n); m_wa2.resize(
n); m_wa3.resize(
n);
305 if (!m_useExternalScaling)
307 eigen_assert( (!m_useExternalScaling || m_diag.size()==
n) &&
"When m_useExternalScaling is set, the caller must provide a valid 'm_diag'");
315 if (
n <= 0 ||
m <
n || m_ftol < 0. || m_xtol < 0. || m_gtol < 0. || m_maxfev <= 0 || m_factor <= 0.){
320 if (m_useExternalScaling)
331 if ( m_functor(
x, m_fvec) < 0)
333 m_fnorm = m_fvec.stableNorm();
342template<
typename FunctorType>
350 m = m_functor.values();
353 if (
n <= 0 ||
m <
n || tol < 0.)
359 m_maxfev = 100*(
n+1);
365template<
typename FunctorType>
375 Index m = functor.values();
378 if (
n <= 0 ||
m <
n || tol < 0.)
Matrix3f m
Definition AngleAxis_mimic_euler.cpp:1
int n
Definition BiCGSTAB_simple.cpp:1
#define eigen_assert(x)
Definition Macros.h:1037
SCALAR Scalar
Definition bench_gemm.cpp:46
NumTraits< Scalar >::Real RealScalar
Definition bench_gemm.cpp:47
Householder rank-revealing QR decomposition of a matrix with column-pivoting.
Definition ColPivHouseholderQR.h:53
Performs non linear optimization over a non-linear function, using a variant of the Levenberg Marquar...
Definition LevenbergMarquardt.h:111
static LevenbergMarquardtSpace::Status lmdif1(FunctorType &functor, FVectorType &x, Index *nfev, const Scalar tol=std::sqrt(NumTraits< Scalar >::epsilon()))
Definition LevenbergMarquardt.h:367
FVectorType & diag()
Definition LevenbergMarquardt.h:197
void setFtol(RealScalar ftol)
Definition LevenbergMarquardt.h:161
FunctorType::QRSolver QRSolver
Definition LevenbergMarquardt.h:114
LevenbergMarquardtSpace::Status minimizeOneStep(FVectorType &x)
Definition LMonestep.h:21
void resetParameters()
Definition LevenbergMarquardt.h:145
RealScalar gtol() const
Definition LevenbergMarquardt.h:185
PermutationMatrix< Dynamic, Dynamic, int > PermutationType
Definition LevenbergMarquardt.h:120
RealScalar xtol() const
Definition LevenbergMarquardt.h:179
RealScalar factor() const
Definition LevenbergMarquardt.h:188
_FunctorType FunctorType
Definition LevenbergMarquardt.h:113
void setFactor(RealScalar factor)
Definition LevenbergMarquardt.h:167
Index njev()
Definition LevenbergMarquardt.h:206
QRSolver::StorageIndex PermIndex
Definition LevenbergMarquardt.h:118
JacobianType & matrixR()
Definition LevenbergMarquardt.h:228
void setEpsilon(RealScalar epsfcn)
Definition LevenbergMarquardt.h:170
FunctorType::JacobianType JacobianType
Definition LevenbergMarquardt.h:115
Index maxfev() const
Definition LevenbergMarquardt.h:194
void setExternalScaling(bool value)
Definition LevenbergMarquardt.h:176
JacobianType & jacobian()
Definition LevenbergMarquardt.h:223
LevenbergMarquardtSpace::Status minimize(FVectorType &x)
Definition LevenbergMarquardt.h:277
PermutationType permutation()
Definition LevenbergMarquardt.h:232
void setXtol(RealScalar xtol)
Definition LevenbergMarquardt.h:158
JacobianType::RealScalar RealScalar
Definition LevenbergMarquardt.h:117
Index nfev
Definition LevenbergMarquardt.h:110
JacobianType::Scalar Scalar
Definition LevenbergMarquardt.h:116
LevenbergMarquardtSpace::Status lmder1(FVectorType &x, const Scalar tol=std::sqrt(NumTraits< Scalar >::epsilon()))
Definition LevenbergMarquardt.h:344
RealScalar ftol() const
Definition LevenbergMarquardt.h:182
FVectorType & fvec()
Definition LevenbergMarquardt.h:219
RealScalar lm_param(void)
Definition LevenbergMarquardt.h:215
RealScalar epsilon() const
Definition LevenbergMarquardt.h:191
RealScalar gnorm()
Definition LevenbergMarquardt.h:212
RealScalar fnorm()
Definition LevenbergMarquardt.h:209
LevenbergMarquardt(FunctorType &functor)
Definition LevenbergMarquardt.h:122
DenseIndex Index
Definition LevenbergMarquardt.h:58
LevenbergMarquardtSpace::Status minimizeInit(FVectorType &x)
Definition LevenbergMarquardt.h:294
void setGtol(RealScalar gtol)
Definition LevenbergMarquardt.h:164
Index nfev()
Definition LevenbergMarquardt.h:203
ComputationInfo info() const
Reports whether the minimization was successful.
Definition LevenbergMarquardt.h:243
Index iterations()
Definition LevenbergMarquardt.h:200
void setMaxfev(Index maxfev)
Definition LevenbergMarquardt.h:173
Matrix< Scalar, Dynamic, 1 > FVectorType
Definition LevenbergMarquardt.h:119
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:180
Definition NumericalDiff.h:37
Permutation matrix.
Definition PermutationMatrix.h:298
A versatible sparse matrix representation.
Definition SparseMatrix.h:98
Sparse left-looking QR factorization with numerical column pivoting.
Definition SparseQR.h:85
Definition XprHelper.h:110
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition gnuplot_common_settings.hh:12
ComputationInfo
Definition Constants.h:440
@ InvalidInput
Definition Constants.h:449
else if n * info
Definition cholesky.cpp:18
Status
Definition LevenbergMarquardt.h:25
@ RelativeReductionTooSmall
Definition LevenbergMarquardt.h:29
@ GtolTooSmall
Definition LevenbergMarquardt.h:36
@ NotStarted
Definition LevenbergMarquardt.h:26
@ UserAsked
Definition LevenbergMarquardt.h:37
@ Running
Definition LevenbergMarquardt.h:27
@ FtolTooSmall
Definition LevenbergMarquardt.h:34
@ TooManyFunctionEvaluation
Definition LevenbergMarquardt.h:33
@ XtolTooSmall
Definition LevenbergMarquardt.h:35
@ CosinusTooSmall
Definition LevenbergMarquardt.h:32
@ RelativeErrorTooSmall
Definition LevenbergMarquardt.h:30
@ ImproperInputParameters
Definition LevenbergMarquardt.h:28
@ RelativeErrorAndReductionTooSmall
Definition LevenbergMarquardt.h:31
void lmpar2(const QRSolver &qr, const VectorType &diag, const VectorType &qtb, typename VectorType::Scalar m_delta, typename VectorType::Scalar &par, VectorType &x)
Definition LMpar.h:20
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
const int Dynamic
Definition Constants.h:22
Definition BandTriangularSolver.h:13
void qr()
Definition qr_colpivoting.cpp:99
Definition LevenbergMarquardt.h:43
Matrix< Scalar, ValuesAtCompileTime, InputsAtCompileTime > JacobianType
Definition LevenbergMarquardt.h:51
const int m_values
Definition LevenbergMarquardt.h:53
int inputs() const
Definition LevenbergMarquardt.h:58
Matrix< Scalar, InputsAtCompileTime, 1 > InputType
Definition LevenbergMarquardt.h:49
const int m_inputs
Definition LevenbergMarquardt.h:53
DenseFunctor()
Definition LevenbergMarquardt.h:55
_Scalar Scalar
Definition LevenbergMarquardt.h:44
Matrix< Scalar, ValuesAtCompileTime, 1 > ValueType
Definition LevenbergMarquardt.h:50
DenseFunctor(int inputs, int values)
Definition LevenbergMarquardt.h:56
ColPivHouseholderQR< JacobianType > QRSolver
Definition LevenbergMarquardt.h:52
int values() const
Definition LevenbergMarquardt.h:59
@ InputsAtCompileTime
Definition LevenbergMarquardt.h:46
@ ValuesAtCompileTime
Definition LevenbergMarquardt.h:47
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition NumTraits.h:233
Definition LevenbergMarquardt.h:70
SparseFunctor(int inputs, int values)
Definition LevenbergMarquardt.h:82
@ ValuesAtCompileTime
Definition LevenbergMarquardt.h:79
@ InputsAtCompileTime
Definition LevenbergMarquardt.h:78
const int m_inputs
Definition LevenbergMarquardt.h:87
_Index Index
Definition LevenbergMarquardt.h:72
int inputs() const
Definition LevenbergMarquardt.h:84
int values() const
Definition LevenbergMarquardt.h:85
SparseQR< JacobianType, COLAMDOrdering< int > > QRSolver
Definition LevenbergMarquardt.h:76
const int m_values
Definition LevenbergMarquardt.h:87
Matrix< Scalar, Dynamic, 1 > ValueType
Definition LevenbergMarquardt.h:74
Matrix< Scalar, Dynamic, 1 > InputType
Definition LevenbergMarquardt.h:73
SparseMatrix< Scalar, ColMajor, Index > JacobianType
Definition LevenbergMarquardt.h:75
_Scalar Scalar
Definition LevenbergMarquardt.h:71
std::ptrdiff_t j
Definition tut_arithmetic_redux_minmax.cpp:2