Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
limit_error_function.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
15
16namespace momentum {
17
24template <typename T>
26 public:
35 const Skeleton& skel,
36 const ParameterTransform& pt,
37 const ParameterLimits& pl = ParameterLimits(),
38 const T& lossAlpha = GeneralizedLossT<T>::kL2,
39 const T& lossC = T(1));
40
48 const Character& character,
49 const T& lossAlpha = GeneralizedLossT<T>::kL2,
50 const T& lossC = T(1));
51
60 const Character& character,
61 const ParameterLimits& pl,
62 const T& lossAlpha = GeneralizedLossT<T>::kL2,
63 const T& lossC = T(1));
64
65 [[nodiscard]] double getError(
66 const ModelParametersT<T>& params,
67 const SkeletonStateT<T>& state,
68 const MeshStateT<T>& meshState) final;
69
71 const ModelParametersT<T>& params,
72 const SkeletonStateT<T>& state,
73 const MeshStateT<T>& meshState,
74 Ref<Eigen::VectorX<T>> gradient) final;
75
77 const ModelParametersT<T>& params,
78 const SkeletonStateT<T>& state,
79 const MeshStateT<T>& meshState,
80 Ref<Eigen::MatrixX<T>> jacobian,
81 Ref<Eigen::VectorX<T>> residual,
82 int& usedRows) final;
83
84 [[nodiscard]] size_t getJacobianSize() const final;
85
86 void setLimits(const ParameterLimits& lm);
87 void setLimits(const Character& character);
88
89 private:
90 // weights for the error functions
91 static constexpr float kLimitWeight = 1e+1;
92 ParameterLimits limits_;
94 const GeneralizedLossT<T> loss_;
95
96 // Implementations of the three public entry points, templated on whether the loss is a plain L2
97 // loss. The L2 path (the default) is compiled with no per-constraint loss-function calls so it
98 // matches the original hand-optimized quadratic penalty with no performance regression; the
99 // non-L2 path applies the generalized loss. getError/getGradient/getJacobian dispatch to these
100 // based on loss_.isL2().
101 template <bool IsL2>
102 [[nodiscard]] double getErrorImpl(
103 const ModelParametersT<T>& params,
104 const SkeletonStateT<T>& state) const;
105
106 template <bool IsL2>
107 [[nodiscard]] double getGradientImpl(
108 const ModelParametersT<T>& params,
109 const SkeletonStateT<T>& state,
110 Ref<Eigen::VectorX<T>> gradient) const;
111
112 template <bool IsL2>
113 double getJacobianImpl(
114 const ModelParametersT<T>& params,
115 const SkeletonStateT<T>& state,
116 Ref<Eigen::MatrixX<T>> jacobian,
117 Ref<Eigen::VectorX<T>> residual,
118 int& usedRows) const;
119};
120
121} // namespace momentum
Implementation of "A General and Adaptive Robust Loss Function" (https://arxiv.org/abs/1701....
static constexpr T kL2
Special-case alpha values that are either at a singularity in the general formula or simplify to a cl...
double getJacobian(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Ref< Eigen::MatrixX< T > > jacobian, Ref< Eigen::VectorX< T > > residual, int &usedRows) final
LimitErrorFunctionT(const Character &character, const ParameterLimits &pl, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
A convenience constructor where character supplies the skeleton and parameter transform,...
void setLimits(const ParameterLimits &lm)
LimitErrorFunctionT(const Character &character, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
A convenience constructor where character contains info of the skeleton, parameter transform,...
LimitErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt, const ParameterLimits &pl=ParameterLimits(), const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
Constructor.
double getGradient(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Ref< Eigen::VectorX< T > > gradient) final
double getError(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState) final
SkeletonErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt)
Definition types.h:28
SkeletonT< float > Skeleton
Definition fwd.h:263
Eigen::Ref< T > Ref
Definition types.h:43
std::vector< ParameterLimit > ParameterLimits
ParameterTransformT< float > ParameterTransform
Definition fwd.h:244
Eigen::Matrix< T, Dynamic, Dynamic > MatrixX
Dynamic-size, column-major dense matrix.
Definition types.h:80
Vector< T, Dynamic > VectorX
Dynamic-size column vector. Common return type for solver residuals and parameter vectors.
Definition types.h:207
A character model with skeletal structure, mesh, and optional components.
Definition character.h:32
Represents the complete state of a model's mesh.
Definition mesh_state.h:24
A vector of size numModelParams holding the values of all model parameters for a character.
Definition types.h:99
Represents the complete state of a skeleton.