|
Momentum
A library for solving nonlinear optimization problems related to human body kinematics
|
Abstract base class for optimization objective functions. More...
#include <solver_function.h>
Public Member Functions | |
| virtual | ~SolverFunctionT ()=default |
| virtual double | getError (const VectorX< T > ¶meters)=0 |
| Evaluates the objective function at the given parameter values. | |
| virtual double | getGradient (const VectorX< T > ¶meters, VectorX< T > &gradient)=0 |
| Computes the gradient of the objective function. | |
| double | getJacobian (const VectorX< T > ¶meters, MatrixX< T > &jacobian, VectorX< T > &residual, size_t &actualRows) |
| Computes the Jacobian matrix for least squares problems. | |
| virtual void | getHessian (const VectorX< T > ¶meters, MatrixX< T > &hessian) |
| Computes the Hessian matrix of second derivatives. | |
| virtual double | getJtJR (const VectorX< T > ¶meters, MatrixX< T > &jtj, VectorX< T > &jtr) |
| Computes JᵀJ and JᵀR for Gauss-Newton optimization. | |
| virtual double | getJtJR_Sparse (const VectorX< T > ¶meters, SparseMatrix< T > &jtj, VectorX< T > &jtr) |
| Computes sparse JᵀJ and JᵀR for large-scale problems. | |
| virtual void | initializeJacobianComputation (const VectorX< T > ¶meters)=0 |
| Initializes Jacobian computation for the given parameters. | |
| virtual size_t | getJacobianBlockCount () const =0 |
| Returns the number of Jacobian blocks available. | |
| virtual size_t | getJacobianBlockSize (size_t blockIndex) const =0 |
| Returns the maximum number of rows for a specific Jacobian block. | |
| virtual double | computeJacobianBlock (const VectorX< T > ¶meters, size_t blockIndex, Eigen::Ref< MatrixX< T > > jacobianBlock, Eigen::Ref< VectorX< T > > residualBlock, size_t &actualRows)=0 |
| Computes a specific Jacobian block. | |
| virtual void | finalizeJacobianComputation () |
| Optional cleanup after all Jacobian blocks have been computed. | |
| virtual double | getSolverDerivatives (const VectorX< T > ¶meters, MatrixX< T > &hess, VectorX< T > &grad) |
| Computes derivatives needed by the solver. | |
| virtual void | updateParameters (VectorX< T > ¶meters, const VectorX< T > &gradient)=0 |
| Updates parameters using the computed step direction. | |
| virtual void | setEnabledParameters (const ParameterSet ¶meterSet) |
| Specifies which parameters should be optimized. | |
| size_t | getNumParameters () const |
| Returns the total number of parameters in the optimization problem. | |
| size_t | getActualParameters () const |
| Returns the number of parameters currently enabled for optimization. | |
| virtual void | storeHistory (std::unordered_map< std::string, MatrixX< T > > &history, size_t iteration, size_t maxIterations_) |
| Records solver state for debugging and analysis. | |
Protected Attributes | |
| size_t | numParameters_ {} |
| Total number of parameters in the optimization problem. | |
| size_t | actualParameters_ {} |
| Number of parameters currently enabled for optimization. | |
| ResizeableMatrix< T > | tJacobian_ |
| Pre-allocated temporary storage for block-wise JtJ computation. | |
| ResizeableMatrix< T > | tResidual_ |
Abstract base class for optimization objective functions.
Provides the interface for computing objective function values, gradients, and other derivatives needed by numerical optimization algorithms.
Definition at line 36 of file solver_function.h.
|
virtualdefault |
|
pure virtual |
Computes a specific Jacobian block.
Must be called after initializeJacobianComputation. The jacobianBlock and residualBlock parameters should be preallocated to the size returned by getJacobianBlockSize.
| parameters | Current parameter values | |
| blockIndex | Index of the block to compute (0 to getJacobianBlockCount()-1) | |
| [out] | jacobianBlock | Jacobian for this block (preallocated) |
| [out] | residualBlock | Residual for this block (preallocated) |
| [out] | actualRows | Number of active rows in this block |
Referenced by getJacobian(), and getJtJR().
|
virtual |
Optional cleanup after all Jacobian blocks have been computed.
Called after all blocks have been processed. Default implementation does nothing.
Reimplemented in momentum::MultiposeSolverFunctionT< T >, momentum::MultiposeSolverFunctionT< double >, momentum::MultiposeSolverFunctionT< float >, momentum::SequenceSolverFunctionT< T >, momentum::SequenceSolverFunctionT< double >, momentum::SequenceSolverFunctionT< float >, momentum::SkeletonSolverFunctionT< T >, momentum::SkeletonSolverFunctionT< double >, and momentum::SkeletonSolverFunctionT< float >.
Definition at line 170 of file solver_function.cpp.
Referenced by getJacobian(), and getJtJR().
|
nodiscard |
Returns the number of parameters currently enabled for optimization.
Definition at line 154 of file solver_function.cpp.
References actualParameters_.
|
pure virtual |
Evaluates the objective function at the given parameter values.
| parameters | Current parameter values |
|
pure virtual |
Computes the gradient of the objective function.
| parameters | Current parameter values | |
| [out] | gradient | Computed gradient vector |
|
virtual |
Computes the Hessian matrix of second derivatives.
Default implementation throws an exception as this is rarely needed
| parameters | Current parameter values | |
| [out] | hessian | Computed Hessian matrix |
Definition at line 15 of file solver_function.cpp.
References MT_THROW.
| double momentum::SolverFunctionT< T >::getJacobian | ( | const VectorX< T > & | parameters, |
| MatrixX< T > & | jacobian, | ||
| VectorX< T > & | residual, | ||
| size_t & | actualRows ) |
Computes the Jacobian matrix for least squares problems.
Default implementation assembles the full Jacobian from blocks using the block-wise interface methods.
| parameters | Current parameter values | |
| [out] | jacobian | Jacobian matrix (m×n for m residuals and n parameters) |
| [out] | residual | Vector of residual values |
| [out] | actualRows | Number of active residual rows |
Definition at line 22 of file solver_function.cpp.
References computeJacobianBlock(), finalizeJacobianComputation(), getJacobianBlockCount(), getJacobianBlockSize(), initializeJacobianComputation(), and momentum::padToSimdAlignment().
Referenced by momentum::d_modelParams_d_inputs().
|
nodiscardpure virtual |
Returns the number of Jacobian blocks available.
Each block corresponds to one error function or constraint group
Implemented in momentum::MultiposeSolverFunctionT< T >, momentum::MultiposeSolverFunctionT< double >, momentum::MultiposeSolverFunctionT< float >, momentum::SequenceSolverFunctionT< T >, momentum::SequenceSolverFunctionT< double >, momentum::SequenceSolverFunctionT< float >, momentum::SkeletonSolverFunctionT< T >, momentum::SkeletonSolverFunctionT< double >, and momentum::SkeletonSolverFunctionT< float >.
Referenced by getJacobian(), and getJtJR().
|
nodiscardpure virtual |
Returns the maximum number of rows for a specific Jacobian block.
This is the maximum size; actual rows may be fewer (returned via actualRows)
| blockIndex | Index of the block (0 to getJacobianBlockCount()-1) |
Implemented in momentum::MultiposeSolverFunctionT< T >, momentum::MultiposeSolverFunctionT< double >, momentum::MultiposeSolverFunctionT< float >, momentum::SequenceSolverFunctionT< T >, momentum::SequenceSolverFunctionT< double >, momentum::SequenceSolverFunctionT< float >, momentum::SkeletonSolverFunctionT< T >, momentum::SkeletonSolverFunctionT< double >, and momentum::SkeletonSolverFunctionT< float >.
Referenced by getJacobian(), and getJtJR().
|
virtual |
Computes JᵀJ and JᵀR for Gauss-Newton optimization.
Default implementation computes these from the Jacobian using the block-wise interface. Derived classes that don't support the block-wise Jacobian interface should override this method to compute JᵀJ and JᵀR directly.
| parameters | Current parameter values | |
| [out] | jtj | Approximated Hessian matrix (JᵀJ) |
| [out] | jtr | Gradient vector (JᵀR) |
Definition at line 74 of file solver_function.cpp.
References actualParameters_, computeJacobianBlock(), finalizeJacobianComputation(), getJacobianBlockCount(), getJacobianBlockSize(), initializeJacobianComputation(), momentum::padToSimdAlignment(), tJacobian_, and tResidual_.
Referenced by getSolverDerivatives().
|
virtual |
Computes sparse JᵀJ and JᵀR for large-scale problems.
Default implementation returns 0.0 and must be overridden for sparse optimization
| parameters | Current parameter values | |
| [out] | jtj | Sparse approximated Hessian matrix |
| [out] | jtr | Gradient vector |
Definition at line 124 of file solver_function.cpp.
|
nodiscard |
Returns the total number of parameters in the optimization problem.
Definition at line 149 of file solver_function.cpp.
References numParameters_.
|
virtual |
Computes derivatives needed by the solver.
Default implementation calls getJtJR
| parameters | Current parameter values | |
| [out] | hess | Hessian matrix or approximation |
| [out] | grad | Gradient vector |
Definition at line 137 of file solver_function.cpp.
References getJtJR().
|
pure virtual |
Initializes Jacobian computation for the given parameters.
Handles expensive one-time setup that can be reused across multiple blocks (e.g., constructing SkeletonState). Must be called before iterating over blocks.
| parameters | Current parameter values |
Referenced by getJacobian(), and getJtJR().
|
virtual |
Specifies which parameters should be optimized.
Default implementation does nothing
| parameterSet | Bitset where each bit indicates if the corresponding parameter is enabled |
Reimplemented in momentum::MultiposeSolverFunctionT< T >, momentum::MultiposeSolverFunctionT< double >, momentum::MultiposeSolverFunctionT< float >, momentum::SequenceSolverFunctionT< T >, momentum::SequenceSolverFunctionT< double >, momentum::SequenceSolverFunctionT< float >, momentum::SkeletonSolverFunctionT< T >, momentum::SkeletonSolverFunctionT< double >, and momentum::SkeletonSolverFunctionT< float >.
Definition at line 146 of file solver_function.cpp.
|
virtual |
Records solver state for debugging and analysis.
| [in,out] | history | Map to store iteration data |
| iteration | Current iteration number | |
| maxIterations | Maximum number of iterations |
Definition at line 159 of file solver_function.cpp.
|
pure virtual |
Updates parameters using the computed step direction.
| [in,out] | parameters | Current parameters, updated in-place |
| gradient | Step direction (typically the negative gradient) |
|
protected |
Number of parameters currently enabled for optimization.
Always less than or equal to numParameters_
Definition at line 185 of file solver_function.h.
Referenced by getActualParameters(), getJtJR(), momentum::SkeletonSolverFunctionT< T >::getSolverDerivatives(), momentum::MultiposeSolverFunctionT< T >::MultiposeSolverFunctionT(), momentum::MultiposeSolverFunctionT< T >::setEnabledParameters(), momentum::SkeletonSolverFunctionT< T >::setEnabledParameters(), and momentum::SkeletonSolverFunctionT< T >::SkeletonSolverFunctionT().
|
protected |
Total number of parameters in the optimization problem.
Definition at line 180 of file solver_function.h.
Referenced by momentum::MultiposeSolverFunctionT< T >::getJoinedParameterVector(), momentum::SequenceSolverFunctionT< T >::getJoinedParameterVectorFromFrameParameters(), getNumParameters(), momentum::MultiposeSolverFunctionT< T >::MultiposeSolverFunctionT(), momentum::SkeletonSolverFunctionT< T >::setEnabledParameters(), and momentum::SkeletonSolverFunctionT< T >::SkeletonSolverFunctionT().
|
protected |
Pre-allocated temporary storage for block-wise JtJ computation.
Uses ResizeableMatrix to avoid reallocations when size fluctuates
Definition at line 190 of file solver_function.h.
Referenced by getJtJR().
|
protected |
Definition at line 191 of file solver_function.h.
Referenced by getJtJR().