30 return "SparseGaussNewton";
38 regularization_ = derivedOptions->regularization;
39 doLineSearch_ = derivedOptions->doLineSearch;
40 useBlockJtJ_ = derivedOptions->useBlockJtJ;
41 directSparseJtJ_ = derivedOptions->directSparseJtJ;
55 Eigen::VectorX<T> delta;
57 if (!directSparseJtJ_) {
68 JtJ_ = hessianApprox_.sparseView();
82 const Eigen::SparseMatrix<T> sjac =
84 JtR_.noalias() = sjac.transpose() * residual_.head(size);
86 JtJ_ = sjac.transpose() * sjac;
93 if (D_.innerSize() !=
static_cast<Eigen::Index
>(this->actualParameters_)) {
97 JtJ_ += D_ * regularization_;
102 lltSolver_.analyzePattern(JtJ_);
109 lltSolver_.factorize(JtJ_);
119 updateParameters(delta);
125 if (lltSolver_.info() != Eigen::Success) {
136void SparseGaussNewtonSolverT<T>::updateParameters(Eigen::VectorX<T>& delta) {
137 if (!doLineSearch_) {
139 this->solverFunction_->updateParameters(this->parameters_, delta);
145 static constexpr T kC1 = 1e-3;
146 static constexpr T kTau = 0.5;
147 static constexpr size_t kMaxLineSearchSteps = 10;
149 const T scaledError = kC1 * this->error_;
150 const Eigen::VectorX<T> parametersOrig = this->parameters_;
151 T lineSearchScale = 1.0;
153 for (
size_t i = 0; i < kMaxLineSearchSteps && std::isnormal(lineSearchScale); ++i) {
154 this->parameters_ = parametersOrig;
156 this->solverFunction_->updateParameters(this->parameters_, lineSearchScale * delta);
158 const double errorNew = this->solverFunction_->getError(this->parameters_);
159 if ((this->error_ - errorNew) >= lineSearchScale * scaledError) {
164 lineSearchScale *= kTau;
Abstract base class for optimization objective functions.
bool newParameterPattern_
Flag indicating parameter structure has changed.
virtual void setOptions(const SolverOptions &options)
Updates solver configuration with new options.
std::unordered_map< std::string, Eigen::MatrixX< T > > iterationHistory_
Recorded data from optimization process.
Eigen::VectorX< T > parameters_
Current parameter values.
bool storeHistory
Whether to record optimization progress for analysis.
double error_
Current objective function value.
size_t numParameters_
Total number of parameters in the optimization problem.
SolverFunctionT< T > * solverFunction_
Function to be optimized.
SolverT(const SolverOptions &options, SolverFunctionT< T > *solver)
Constructor with solver options and function to optimize.
int actualParameters_
Number of parameters currently enabled for optimization.
Sparse implementation of the Gauss-Newton optimization algorithm.
std::string_view getName() const override
Returns "SparseGaussNewton" as the solver name.
void setOptions(const SolverOptions &options) final
Updates solver configuration, handling both base and sparse Gauss-Newton specific options.
void initializeSolver() final
Initializes solver state before optimization begins.
void doIteration() final
Performs one iteration of the sparse Gauss-Newton algorithm.
SparseGaussNewtonSolverT(const SolverOptions &options, SolverFunctionT< T > *solver)
Creates a solver with the specified options and function to optimize.
Profiling macros that dispatch to one of three backends, selected at compile time:
#define MT_PROFILE_EVENT(NAME)
#define MT_PROFILE_FUNCTION()
Common options for numerical optimization solvers.
Extended options specific to the sparse Gauss-Newton optimization algorithm.
float regularization
Damping parameter added to Hessian diagonal for numerical stability; see https://en....
bool doLineSearch
Enables backtracking line search to ensure error reduction at each step.