19 template <
typename QRSolver,
typename VectorType>
24 typename VectorType::Scalar m_delta,
25 typename VectorType::Scalar &par,
31 typedef typename QRSolver::MatrixType MatrixType;
32 typedef typename QRSolver::Scalar Scalar;
50 const Scalar dwarf = (std::numeric_limits<Scalar>::min)();
51 const Index n = qr.matrixR().cols();
61 const Index rank = qr.rank();
63 wa1.tail(n-rank).setZero();
65 wa1.head(rank) = s.topLeftCorner(rank,rank).template triangularView<Upper>().solve(qtb.head(rank));
67 x = qr.colsPermutation()*wa1;
73 wa2 = diag.cwiseProduct(x);
74 dxnorm = wa2.blueNorm();
75 fp = dxnorm - m_delta;
76 if (fp <= Scalar(0.1) * m_delta) {
86 wa1 = qr.colsPermutation().inverse() * diag.cwiseProduct(wa2)/dxnorm;
87 s.topLeftCorner(n,n).transpose().template triangularView<Lower>().solveInPlace(wa1);
88 temp = wa1.blueNorm();
89 parl = fp / m_delta / temp / temp;
93 for (j = 0; j < n; ++j)
94 wa1[j] = s.col(j).head(j+1).dot(qtb.head(j+1)) / diag[qr.colsPermutation().indices()(j)];
96 gnorm = wa1.stableNorm();
97 paru = gnorm / m_delta;
99 paru = dwarf / (std::min)(m_delta,Scalar(0.1));
104 par = (std::min)(par,paru);
106 par = gnorm / dxnorm;
114 par = (
std::max)(dwarf,Scalar(.001) * paru);
115 wa1 =
sqrt(par)* diag;
118 lmqrsolv(s, qr.colsPermutation(), wa1, qtb, x, sdiag);
120 wa2 = diag.cwiseProduct(x);
121 dxnorm = wa2.blueNorm();
123 fp = dxnorm - m_delta;
128 if (
abs(fp) <= Scalar(0.1) * m_delta || (parl == 0. && fp <= temp && temp < 0.) || iter == 10)
132 wa1 = qr.colsPermutation().inverse() * diag.cwiseProduct(wa2/dxnorm);
134 for (j = 0; j < n; ++j) {
137 for (
Index i = j+1; i < n; ++i)
138 wa1[i] -= s.coeff(i,j) * temp;
140 temp = wa1.blueNorm();
141 parc = fp / m_delta / temp / temp;
147 paru = (std::min)(paru,par);
160 #endif // EIGEN_LMPAR_H void lmpar2(const QRSolver &qr, const VectorType &diag, const VectorType &qtb, typename VectorType::Scalar m_delta, typename VectorType::Scalar &par, VectorType &x)
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
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_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
void lmqrsolv(Matrix< Scalar, Rows, Cols > &s, const PermutationMatrix< Dynamic, Dynamic, PermIndex > &iPerm, const Matrix< Scalar, Dynamic, 1 > &diag, const Matrix< Scalar, Dynamic, 1 > &qtb, Matrix< Scalar, Dynamic, 1 > &x, Matrix< Scalar, Dynamic, 1 > &sdiag)