Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
gradient_descent_solver.cpp
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
9
12
13namespace momentum {
14
15template <typename T>
17 const SolverOptions& options,
18 SolverFunctionT<T>* solver)
19 : SolverT<T>(options, solver) {
20 // Set default values from GradientDescentSolverOptions
22
23 // Update values based on provided options
24 setOptions(options);
25}
26
27template <typename T>
28std::string_view GradientDescentSolverT<T>::getName() const {
29 return "GradientDescent";
30}
31
32template <typename T>
35
36 if (const auto* derivedOptions = dynamic_cast<const GradientDescentSolverOptions*>(&options)) {
37 learningRate_ = derivedOptions->learningRate;
38 }
39}
40
41template <typename T>
43
44template <typename T>
47 this->error_ = this->solverFunction_->getGradient(this->parameters_, gradient_);
48 this->solverFunction_->updateParameters(this->parameters_, gradient_ * learningRate_);
49}
50
53
54} // namespace momentum
First-order optimization algorithm that follows the negative gradient.
void initializeSolver() final
Initializes solver state before optimization begins.
GradientDescentSolverT(const SolverOptions &options, SolverFunctionT< T > *solver)
Creates a solver with the specified options and function to optimize.
void setOptions(const SolverOptions &options) final
Updates solver configuration, handling both base and Gradient Descent specific options.
void doIteration() final
Performs one iteration of the gradient descent algorithm.
std::string_view getName() const override
Returns "GradientDescent" as the solver name.
Abstract base class for optimization objective functions.
virtual void setOptions(const SolverOptions &options)
Updates solver configuration with new options.
Definition solver.cpp:32
Eigen::VectorX< T > parameters_
Current parameter values.
Definition solver.h:109
double error_
Current objective function value.
Definition solver.h:126
SolverFunctionT< T > * solverFunction_
Function to be optimized.
Definition solver.h:106
SolverT(const SolverOptions &options, SolverFunctionT< T > *solver)
Constructor with solver options and function to optimize.
Definition solver.cpp:20
Profiling macros that dispatch to one of three backends, selected at compile time:
#define MT_PROFILE_FUNCTION()
Definition profile.h:110
Extended options for the Gradient Descent optimization algorithm.
float learningRate
Step size for parameter updates during optimization.
Common options for numerical optimization solvers.
Definition solver.h:19