Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
gauss_newton_solver.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#pragma once
9
11#include <momentum/solver/fwd.h>
13
14namespace momentum {
15
22 float regularization = 0.05f;
23
25 bool doLineSearch = false;
26
29
31 /* implicit */ GaussNewtonSolverBaseOptions(const SolverOptions& baseOptions)
32 : SolverOptions(baseOptions) {}
33};
34
40 bool useBlockJtJ = false;
41
51 size_t targetRowsPerChunk = SIZE_MAX;
52
55
57 /* implicit */ GaussNewtonSolverOptions(const SolverOptions& baseOptions)
58 : GaussNewtonSolverBaseOptions(baseOptions) {}
59};
60
66template <typename T>
67class GaussNewtonSolverT : public SolverT<T> {
68 public:
71
73 [[nodiscard]] std::string_view getName() const override;
74
76 void setOptions(const SolverOptions& options) final;
77
78 // Testing/debug accessors
79 const Eigen::MatrixX<T>& getLastJtJ() const {
80 return hessianApprox_;
81 }
82 const Eigen::VectorX<T>& getLastJtR() const {
83 return JtR_;
84 }
85
86 protected:
88 void doIteration() final;
89
91 void initializeSolver() final;
92
93 private:
97 void updateParameters(Eigen::VectorX<T>& delta);
98
100 void updateEnabledParameters();
101
103 void computeJtJFromBlockJtJ();
104
106 void computeJtJFromJacobianBlocks();
107
109 bool useBlockJtJ_{};
110
112 bool doLineSearch_;
113
115 ResizeableMatrix<T> jacobian_;
116
118 ResizeableMatrix<T> residual_;
119
121 size_t targetRowsPerChunk_;
122
124 Eigen::MatrixX<T> hessianApprox_;
125
127 Eigen::VectorX<T> JtR_;
128
130 Eigen::LLT<Eigen::MatrixX<T>> llt_;
131
133 T regularization_;
134
136 std::vector<int> enabledParameters_;
137};
138
139} // namespace momentum
GaussNewtonSolverT(const SolverOptions &options, SolverFunctionT< T > *solver)
Creates a solver with the specified options and function to optimize.
const Eigen::VectorX< T > & getLastJtR() const
const Eigen::MatrixX< T > & getLastJtJ() const
void setOptions(const SolverOptions &options) final
Updates solver configuration, handling both base and Gauss-Newton specific options.
void doIteration() final
Performs one iteration of the Gauss-Newton algorithm.
std::string_view getName() const override
Returns "GaussNewton" as the solver name.
A dense column-major matrix whose underlying storage capacity grows monotonically and is reused acros...
Abstract base class for optimization objective functions.
SolverT(const SolverOptions &options, SolverFunctionT< T > *solver)
Constructor with solver options and function to optimize.
Definition solver.cpp:20
Definition types.h:28
Vector< T, Dynamic > VectorX
Dynamic-size column vector. Common return type for solver residuals and parameter vectors.
Definition types.h:207
GaussNewtonSolverBaseOptions()=default
Default constructor.
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.
GaussNewtonSolverBaseOptions(const SolverOptions &baseOptions)
Construct from base solver options while preserving Gauss-Newton defaults.
bool useBlockJtJ
Uses pre-computed JᵀJ and JᵀR from the solver function.
GaussNewtonSolverOptions()=default
Default constructor.
GaussNewtonSolverOptions(const SolverOptions &baseOptions)
Construct from base solver options while preserving Gauss-Newton defaults.
size_t targetRowsPerChunk
Target number of Jacobian rows to accumulate before computing JᵀJ.
Common options for numerical optimization solvers.
Definition solver.h:19