|
Momentum
A library for solving nonlinear optimization problems related to human body kinematics
|
Implementation of "A General and Adaptive Robust Loss Function" (https://arxiv.org/abs/1701.03077). More...
#include <generalized_loss.h>
Public Member Functions | |
| GeneralizedLossT (const T &a=kL2, const T &c=T(1)) | |
Constructs a generalized loss with shape a and scale c. | |
| T | value (const T &sqrError) const |
| Returns the loss value for a given squared error. | |
| T | deriv (const T &sqrError) const |
| Derivative of the loss with respect to the input squared error. | |
| bool | isL2 () const |
| Returns true if this loss is an L2 loss (alpha ~= 2). | |
| T | invC2 () const |
| Returns the stored 1/c^2 value. For default c=1, this is 1.0. | |
Static Public Attributes | |
| static constexpr T | kL2 = T(2) |
| Special-case alpha values that are either at a singularity in the general formula or simplify to a closed-form computation. | |
| static constexpr T | kL1 = T(1) |
| static constexpr T | kCauchy = T(0) |
| static constexpr T | kWelsch = std::numeric_limits<T>::lowest() |
| Sentinel for the Welsch (alpha -> -inf) limit. | |
Protected Types | |
| enum class | LossType { L1 , L2 , Cauchy , Welsch , General } |
Protected Attributes | |
| const T | alpha_ |
| const T | invC2_ |
| Stored as 1/c^2 (instead of c) as a small optimization, since the loss formulas use this quantity directly. | |
| LossType | lossType_ |
Static Protected Attributes | |
| static constexpr T | kEps = 1e-9 |
| Small threshold used to detect proximity to special-case alpha values. | |
Implementation of "A General and Adaptive Robust Loss Function" (https://arxiv.org/abs/1701.03077).
This loss transforms a squared error value with parameters alpha and c. alpha can be approximately thought of as the norm: alpha=2 is the squared L2 norm loss; alpha=1 is a soft L1 norm or the L2-L1/pseudo-Huber loss. alpha controls the effect of "outliers" (i.e., "robust"). Smaller alpha reduces the contribution of large errors so they don't affect the result as much. c scales the gradient with respect to the squared error term inversely.
This does not implement solving for alpha. It assumes alpha and c are given as input.
The c parameter controls the transition scale: residuals << c behave like L2, residuals >> c are downweighted according to the loss shape.
In the Gauss-Newton solver, the loss function modifies both the residual and Jacobian via the chain rule. The SimdGeneralizedLoss class handles this vectorized computation for SIMD error functions. Generic error functions apply the loss via the JointErrorFunctionT base class automatically — subclasses implement evalFunction() with raw residuals.
Definition at line 46 of file generalized_loss.h.
|
strongprotected |
| Enumerator | |
|---|---|
| L1 | |
| L2 | |
| Cauchy | |
| Welsch | |
| General | |
Definition at line 92 of file generalized_loss.h.
| momentum::GeneralizedLossT< T >::GeneralizedLossT | ( | const T & | a = kL2, |
| const T & | c = T(1) ) |
Constructs a generalized loss with shape a and scale c.
| a | Shape parameter alpha. Theoretically unbounded, but values with very large magnitude (e.g., > 100) are numerically unstable and not needed in practice. Use kWelsch to select the Welsch negative-infinity limit. |
| c | Scale parameter. Must be > 0. Very small values are unstable because the gradient scales with 1/c^2. |
Definition at line 81 of file generalized_loss.cpp.
References alpha_, Cauchy, General, invC2_, kCauchy, kEps, kL1, kL2, kWelsch, L1, L2, lossType_, MT_CHECK, and Welsch.
|
nodiscard |
|
inlinenodiscard |
Returns the stored 1/c^2 value. For default c=1, this is 1.0.
Definition at line 87 of file generalized_loss.h.
|
inlinenodiscard |
Returns true if this loss is an L2 loss (alpha ~= 2).
Useful for fast-path optimizations that bypass value()/deriv() calls.
Definition at line 82 of file generalized_loss.h.
|
nodiscard |
|
protected |
Definition at line 103 of file generalized_loss.h.
Referenced by deriv(), momentum::SimdGeneralizedLossT< T >::deriv(), GeneralizedLossT(), value(), and momentum::SimdGeneralizedLossT< T >::value().
|
protected |
Stored as 1/c^2 (instead of c) as a small optimization, since the loss formulas use this quantity directly.
Definition at line 107 of file generalized_loss.h.
Referenced by deriv(), momentum::SimdGeneralizedLossT< T >::deriv(), GeneralizedLossT(), value(), and momentum::SimdGeneralizedLossT< T >::value().
|
staticconstexpr |
Definition at line 52 of file generalized_loss.h.
Referenced by GeneralizedLossT().
|
staticconstexprprotected |
Small threshold used to detect proximity to special-case alpha values.
Definition at line 101 of file generalized_loss.h.
Referenced by GeneralizedLossT().
|
staticconstexpr |
Definition at line 51 of file generalized_loss.h.
Referenced by GeneralizedLossT().
|
staticconstexpr |
Special-case alpha values that are either at a singularity in the general formula or simplify to a closed-form computation.
Definition at line 50 of file generalized_loss.h.
Referenced by momentum::AimDirErrorFunctionT< float >::AimDirErrorFunctionT(), momentum::AimDirErrorFunctionT< float >::AimDirErrorFunctionT(), momentum::AimDistErrorFunctionT< float >::AimDistErrorFunctionT(), momentum::AimDistErrorFunctionT< float >::AimDistErrorFunctionT(), momentum::FixedAxisAngleErrorFunctionT< float >::FixedAxisAngleErrorFunctionT(), momentum::FixedAxisAngleErrorFunctionT< float >::FixedAxisAngleErrorFunctionT(), momentum::FixedAxisCosErrorFunctionT< float >::FixedAxisCosErrorFunctionT(), momentum::FixedAxisCosErrorFunctionT< float >::FixedAxisCosErrorFunctionT(), momentum::FixedAxisDiffErrorFunctionT< float >::FixedAxisDiffErrorFunctionT(), momentum::FixedAxisDiffErrorFunctionT< float >::FixedAxisDiffErrorFunctionT(), GeneralizedLossT(), momentum::JointErrorFunctionT< T, Data, FuncDim, NumVec, NumPos >::JointErrorFunctionT(), momentum::LimitErrorFunctionT< float >::LimitErrorFunctionT(), momentum::LimitErrorFunctionT< float >::LimitErrorFunctionT(), momentum::LimitErrorFunctionT< float >::LimitErrorFunctionT(), momentum::NormalErrorFunctionT< float >::NormalErrorFunctionT(), momentum::NormalErrorFunctionT< float >::NormalErrorFunctionT(), momentum::OrientationErrorFunctionT< float >::OrientationErrorFunctionT(), momentum::OrientationErrorFunctionT< float >::OrientationErrorFunctionT(), momentum::OrientationRotDiffErrorFunctionT< float >::OrientationRotDiffErrorFunctionT(), momentum::OrientationRotDiffErrorFunctionT< float >::OrientationRotDiffErrorFunctionT(), momentum::PlaneErrorFunctionT< float >::PlaneErrorFunctionT(), momentum::PlaneErrorFunctionT< float >::PlaneErrorFunctionT(), momentum::PositionErrorFunctionT< float >::PositionErrorFunctionT(), momentum::PositionErrorFunctionT< float >::PositionErrorFunctionT(), momentum::VertexErrorFunctionT< T, VertexNormalDataT< T >, 1 >::VertexErrorFunctionT(), momentum::VertexNormalErrorFunctionT< float >::VertexNormalErrorFunctionT(), momentum::VertexPlaneErrorFunctionT< float >::VertexPlaneErrorFunctionT(), momentum::VertexPositionErrorFunctionT< float >::VertexPositionErrorFunctionT(), and momentum::VertexProjectionErrorFunctionT< float >::VertexProjectionErrorFunctionT().
|
staticconstexpr |
Sentinel for the Welsch (alpha -> -inf) limit.
Pass this as alpha to opt into the Welsch closed form. This uses the finite lowest value instead of an infinity literal so fast-math builds that disable infinities can still compile the public header. Other finite negative alphas (e.g. -2 for Geman-McClure) are evaluated by the LossType::General branch and are NOT silently rerouted to Welsch.
Definition at line 58 of file generalized_loss.h.
Referenced by GeneralizedLossT().
|
protected |
Definition at line 109 of file generalized_loss.h.
Referenced by deriv(), momentum::SimdGeneralizedLossT< T >::deriv(), GeneralizedLossT(), value(), and momentum::SimdGeneralizedLossT< T >::value().