50 const Eigen::MatrixBase<D2> & d,
51 const Eigen::MatrixBase<D3> & r,
53 std::optional<std::reference_wrapper<double>> dphi = {})
54 -> Eigen::Vector<
typename std::decay_t<
decltype(J)>
::Scalar, std::decay_t<
decltype(J)>::ColsAtCompileTime>
56 using JType = std::decay_t<
decltype(J)>;
57 using Scalar =
typename JType::Scalar;
58 static constexpr auto N = JType::ColsAtCompileTime;
60 static constexpr bool is_sparse = std::is_base_of_v<Eigen::SparseMatrixBase<JType>, JType>;
63 conditional_t<is_sparse, Eigen::SparseMatrix<typename JType::Scalar>, Eigen::Matrix<typename JType::Scalar, N, N>>;
65 using LDLTt = std::conditional_t<is_sparse, Eigen::SimplicialLDLT<Ht>, Eigen::LDLT<Ht>>;
67 Ht H = J.transpose() * J;
68 for (
auto i = 0u; i < H.rows(); ++i) { H.coeffRef(i, i) += lambda * d(i) * d(i); }
71 const Eigen::Vector<Scalar, N> x = ldlt.solve(-J.transpose() * r);
73 if (dphi.has_value()) {
74 const Eigen::Vector<Scalar, N> Dx = -d.cwiseProduct(x);
75 const Eigen::Vector<Scalar, N> d_q = d.cwiseProduct(Dx);
76 const Eigen::Vector<Scalar, N> y = ldlt.solve(d_q);
77 dphi->get() = -d.cwiseProduct(Dx.normalized()).dot(y);
SMOOTH_BEGIN_NAMESPACE auto solve_linear_ldlt(const auto &J, const Eigen::MatrixBase< D2 > &d, const Eigen::MatrixBase< D3 > &r, const double lambda, std::optional< std::reference_wrapper< double > > dphi={}) -> Eigen::Vector< typename std::decay_t< decltype(J)>::Scalar, std::decay_t< decltype(J)>::ColsAtCompileTime >
Solve least-squares problem using LDL' decomposition.
auto solve_trust_region(const auto &J, const Eigen::MatrixBase< D2 > &d, const Eigen::MatrixBase< D3 > &r, const double Delta) -> std::pair< Eigen::Vector< typename std::decay_t< decltype(J)>::Scalar, std::decay_t< decltype(J)>::ColsAtCompileTime >, double >
Approximately solve trust-region step determination problem.