14 #ifndef EIGEN_LMONESTEP_H 15 #define EIGEN_LMONESTEP_H 19 template<
typename FunctorType>
27 RealScalar pnorm, xnorm, fnorm1, actred, dirder, prered;
30 temp = 0.0; xnorm = 0.0;
32 Index df_ret = m_functor.df(x, m_fjac);
41 for (
int j = 0; j < x.size(); ++j)
42 m_wa2(j) = m_fjac.col(j).blueNorm();
49 m_rfactor = qrfac.matrixR();
50 m_permutation = (qrfac.colsPermutation());
55 if (!m_useExternalScaling)
56 for (
Index j = 0; j < n; ++j)
57 m_diag[j] = (m_wa2[j]==0.)? 1. : m_wa2[j];
61 xnorm = m_diag.cwiseProduct(x).stableNorm();
62 m_delta = m_factor * xnorm;
70 m_wa4 = qrfac.matrixQ().adjoint() * m_fvec;
71 m_qtf = m_wa4.head(n);
76 for (
Index j = 0; j < n; ++j)
77 if (m_wa2[m_permutation.indices()[j]] != 0.)
78 m_gnorm = (
std::max)(m_gnorm,
abs( m_rfactor.col(j).head(j+1).dot(m_qtf.head(j+1)/m_fnorm) / m_wa2[m_permutation.indices()[j]]));
81 if (m_gnorm <= m_gtol) {
87 if (!m_useExternalScaling)
88 m_diag = m_diag.cwiseMax(m_wa2);
97 pnorm = m_diag.cwiseProduct(m_wa1).stableNorm();
101 m_delta = (std::min)(m_delta,pnorm);
104 if ( m_functor(m_wa2, m_wa4) < 0)
107 fnorm1 = m_wa4.stableNorm();
111 if (
Scalar(.1) * fnorm1 < m_fnorm)
116 m_wa3 = m_rfactor.template triangularView<Upper>() * (m_permutation.inverse() *m_wa1);
119 prered = temp1 + temp2 /
Scalar(.5);
120 dirder = -(temp1 + temp2);
126 ratio = actred / prered;
129 if (ratio <=
Scalar(.25)) {
137 m_delta = temp * (std::min)(m_delta, pnorm /
RealScalar(.1));
139 }
else if (!(m_par != 0. && ratio <
RealScalar(.75))) {
148 m_wa2 = m_diag.cwiseProduct(x);
150 xnorm = m_wa2.stableNorm();
156 if (
abs(actred) <= m_ftol && prered <= m_ftol &&
Scalar(.5) * ratio <= 1. && m_delta <= m_xtol * xnorm)
161 if (
abs(actred) <= m_ftol && prered <= m_ftol &&
Scalar(.5) * ratio <= 1.)
166 if (m_delta <= m_xtol * xnorm)
173 if (m_nfev >= m_maxfev)
194 }
while (ratio <
Scalar(1e-4));
202 #endif // EIGEN_LMONESTEP_H JacobianType::RealScalar RealScalar
LevenbergMarquardtSpace::Status minimizeOneStep(FVectorType &x)
void lmpar2(const QRSolver &qr, const VectorType &diag, const VectorType &qtb, typename VectorType::Scalar m_delta, typename VectorType::Scalar &par, VectorType &x)
JacobianType::Scalar Scalar
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const AbsReturnType abs() const
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half() max(const half &a, const half &b)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Abs2ReturnType abs2() const
FunctorType::QRSolver QRSolver