Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
gauss_newton_solver_sparse.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
10#include <momentum/solver/fwd.h>
12
13namespace momentum {
14
21 float regularization = 0.05f;
22
24 bool doLineSearch = false;
25
29 bool useBlockJtJ = false;
30
34 bool directSparseJtJ = false;
35
38
40 /* implicit */ SparseGaussNewtonSolverOptions(const SolverOptions& baseOptions)
41 : SolverOptions(baseOptions) {}
42};
43
49template <typename T>
51 public:
54
56 [[nodiscard]] std::string_view getName() const override;
57
59 void setOptions(const SolverOptions& options) final;
60
61 protected:
63 void doIteration() final;
64
66 void initializeSolver() final;
67
68 private:
72 void updateParameters(Eigen::VectorX<T>& delta);
73
75 bool useBlockJtJ_{};
76
78 bool directSparseJtJ_{};
79
81 bool doLineSearch_;
82
84 Eigen::SimplicialLLT<Eigen::SparseMatrix<T>, Eigen::Lower> lltSolver_;
85
87 Eigen::SparseMatrix<T> JtJ_;
88
90 Eigen::SparseMatrix<T> D_;
91
93 Eigen::MatrixX<T> jacobian_;
94
96 Eigen::MatrixX<T> hessianApprox_;
97
99 Eigen::VectorX<T> JtR_;
100
102 Eigen::VectorX<T> residual_;
103
105 T regularization_;
106};
107
108} // namespace momentum
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
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 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.
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
Common options for numerical optimization solvers.
Definition solver.h:19
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.
bool directSparseJtJ
Directly computes sparse JᵀJ without dense intermediate representation.
SparseGaussNewtonSolverOptions()=default
Default constructor.
bool useBlockJtJ
Uses pre-computed JᵀJ and JᵀR from the solver function.
SparseGaussNewtonSolverOptions(const SolverOptions &baseOptions)
Construct from base solver options while preserving defaults.