22 this->initialized_ =
false;
30 updateEnabledParameters();
35 return "SubsetGaussNewton";
43 regularization_ = derivedOptions->regularization;
44 doLineSearch_ = derivedOptions->doLineSearch;
49void SubsetGaussNewtonSolverT<T>::updateEnabledParameters() {
50 const auto nFullParams = this->parameters_.size();
51 this->enabledParameters_.clear();
52 this->enabledParameters_.reserve(nFullParams);
53 for (
int iFullParam = 0; iFullParam < nFullParams; ++iFullParam) {
54 if (this->activeParameters_.test(iFullParam)) {
55 this->enabledParameters_.push_back(iFullParam);
60 const int nSubsetParams = gsl::narrow_cast<int>(this->enabledParameters_.size());
61 this->subsetHessian_.resize(nSubsetParams, nSubsetParams);
62 subsetDelta_.resize(nSubsetParams);
68 updateEnabledParameters();
76 size_t jacobianRows = 0;
78 this->
parameters_, this->jacobian_, this->residual_, jacobianRows);
79 const double error_orig = this->
error_;
81 const int nSubsetParams = gsl::narrow_cast<int>(this->enabledParameters_.size());
90 for (
int iSubsetParam = 0; iSubsetParam < nSubsetParams; ++iSubsetParam) {
92 if (this->enabledParameters_[iSubsetParam] > iSubsetParam) {
93 this->jacobian_.col(iSubsetParam) =
94 this->jacobian_.col(this->enabledParameters_[iSubsetParam]);
98 const auto JBlock = this->jacobian_.topLeftCorner(jacobianRows, nSubsetParams);
103 this->subsetGradient_.noalias() = this->residual_.head(jacobianRows).transpose() * JBlock;
106 this->subsetHessian_.template triangularView<Eigen::Lower>() = JBlock.transpose() * JBlock;
107 this->subsetHessian_.diagonal().array() += this->regularization_;
110 subsetDelta_.noalias() = llt_.compute(this->subsetHessian_).solve(subsetGradient_);
114 for (
int iSubsetParam = 0; iSubsetParam < nSubsetParams; ++iSubsetParam) {
115 const int iFullParam = this->enabledParameters_[iSubsetParam];
116 delta_(iFullParam) = subsetDelta_(iSubsetParam);
120 const double innerProd = -this->subsetGradient_.dot(subsetDelta_);
123 const float c_1 = 1e-4F;
124 const float tau = 0.5F;
127 const Eigen::VectorX<T> parameters_orig = this->
parameters_;
128 for (
size_t kStep = 0; kStep < 10 && std::fpclassify(alpha) == FP_NORMAL; ++kStep) {
135 if ((error_orig - error_new) >= c_1 * alpha * -innerProd) {
Abstract base class for optimization objective functions.
virtual void setOptions(const SolverOptions &options)
Updates solver configuration with new options.
Eigen::VectorX< T > parameters_
Current parameter values.
double error_
Current objective function value.
SolverFunctionT< T > * solverFunction_
Function to be optimized.
virtual void setEnabledParameters(const ParameterSet ¶meters)
Specifies which parameters should be optimized.
SolverT(const SolverOptions &options, SolverFunctionT< T > *solver)
Constructor with solver options and function to optimize.
Gauss-Newton solver that optimizes only a selected subset of parameters.
void doIteration() final
Performs one iteration of the Subset Gauss-Newton algorithm.
void setOptions(const SolverOptions &options) final
Updates solver configuration, handling both base and Subset Gauss-Newton specific options.
void initializeSolver() final
Initializes solver state before optimization begins.
std::string_view getName() const override
Returns "SubsetGaussNewton" as the solver name.
void setEnabledParameters(const ParameterSet ¶meters) final
Specifies which parameters should be optimized.
SubsetGaussNewtonSolverT(const SolverOptions &options, SolverFunctionT< T > *solver)
Creates a solver with the specified options and function to optimize.
std::bitset< kMaxModelParams > ParameterSet
Bitset for model parameter enablement.
Profiling macros that dispatch to one of three backends, selected at compile time:
#define MT_PROFILE_FUNCTION()
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.
Common options for numerical optimization solvers.
Extended options for the Subset Gauss-Newton optimization algorithm.