Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
sequence_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
13#include <momentum/common/fwd.h>
14#include <momentum/math/fwd.h>
16
17#include <functional>
18#include <span>
19
20namespace momentum {
21
25
26 /* implicit */ SequenceSolverOptions(const SolverOptions& baseOptions)
27 : SequenceSolverOptionsBase(baseOptions) {
28 // Empty
29 }
30};
31
32template <typename T>
34 public:
36
37 [[nodiscard]] std::string_view getName() const override;
38
39 void setOptions(const SolverOptions& options) final;
40
41 void iter() {
43 this->iteration_++;
44 }
45
46 void init() {
47 this->iteration_ = 0;
49 }
50
51 Eigen::VectorX<T> getP() {
52 return this->parameters_;
53 }
54
55 protected:
56 void doIteration() final;
57 void initializeSolver() final;
58
59 private:
60 static double processPerFrameErrors_parallel(
62 OnlineBandedHouseholderQR<T>& qrSolver,
63 ProgressBar* progress);
64 static double processPerFrameErrors_serial(
66 OnlineBandedHouseholderQR<T>& qrSolver,
67 ProgressBar* progress);
68
69 static double processSequenceErrors_serial(
71 OnlineBandedHouseholderQR<T>& qrSolver,
72 ProgressBar* progress);
73
74 struct JacobianResidual {
75 size_t frameIndex = SIZE_MAX;
76 Eigen::MatrixX<T> jacobian;
77 Eigen::VectorX<T> residual;
78 double error = 0.0;
79 size_t nFunctions = 0;
80 Eigen::Index usedRows = 0;
81
82 bool operator<(const JacobianResidual& rhs) const {
83 return frameIndex < rhs.frameIndex;
84 }
85
86 bool operator>(const JacobianResidual& rhs) const {
87 return frameIndex > rhs.frameIndex;
88 }
89 };
90
91 // Here, the processJac function computes the Jacobian/residual, applies it to the banded
92 // part of the matrix, and then returns the universal part.
93 static double processErrorFunctions_parallel(
94 const std::function<JacobianResidual(
95 size_t,
98 SkeletonStateT<T> skelState,
99 MeshStateT<T>& meshState)>& processJac,
102 ProgressBar* progress);
103
104 // Returns the [Jacobian, residual, error] for all the error functions applying to a single frame:
105 static JacobianResidual computePerFrameJacobian(
107 size_t iFrame,
108 SkeletonStateT<T>& skelState,
109 MeshStateT<T>& meshState);
110
111 // Returns the [Jacobian, residual, error] for all the sequence error functions starting from a
112 // single frame:
113 static JacobianResidual computeSequenceJacobian(
115 size_t iFrame,
116 size_t bandwidth,
117 std::span<const SkeletonStateT<T>> skelStates,
118 std::span<const MeshStateT<T>> meshStates);
119};
120
121} // namespace momentum
Online Householder QR solver for band-plus-arrowhead matrices.
A terminal progress bar rendered as Name [===> ] 60%.
SequenceSolverBaseT(const SolverOptions &options, SequenceSolverFunctionT< T > *function)
Eigen::VectorX< T > getP()
void initializeSolver() final
Initializes solver state before optimization begins.
SequenceSolverT(const SolverOptions &options, SequenceSolverFunctionT< T > *function)
std::string_view getName() const override
Returns the name of the solver implementation.
void doIteration() final
Performs a single iteration of the optimization algorithm.
void setOptions(const SolverOptions &options) final
Updates solver configuration with new options.
Eigen::VectorX< float > parameters_
Definition solver.h:109
Represents the complete state of a model's mesh.
Definition mesh_state.h:24
SequenceSolverOptions(const SolverOptions &baseOptions)
Represents the complete state of a skeleton.
Common options for numerical optimization solvers.
Definition solver.h:19