Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
generalized_loss.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
10#include <limits>
11
12namespace momentum {
13
45template <typename T>
47 public:
50 static constexpr T kL2 = T(2);
51 static constexpr T kL1 = T(1);
52 static constexpr T kCauchy = T(0);
58 static constexpr T kWelsch = std::numeric_limits<T>::lowest();
59
70 GeneralizedLossT(const T& a = kL2, const T& c = T(1));
71
74 [[nodiscard]] T value(const T& sqrError) const;
75
78 [[nodiscard]] T deriv(const T& sqrError) const;
79
82 [[nodiscard]] bool isL2() const {
83 return lossType_ == LossType::L2;
84 }
85
87 [[nodiscard]] T invC2() const {
88 return invC2_;
89 }
90
91 protected:
99
101 static constexpr T kEps = 1e-9;
102
103 const T alpha_;
104
107 const T invC2_;
108
110};
111} // namespace momentum
bool isL2() const
Returns true if this loss is an L2 loss (alpha ~= 2).
T value(const T &sqrError) const
Returns the loss value for a given squared error.
T invC2() const
Returns the stored 1/c^2 value. For default c=1, this is 1.0.
T deriv(const T &sqrError) const
Derivative of the loss with respect to the input squared error.
GeneralizedLossT(const T &a=kL2, const T &c=T(1))
Constructs a generalized loss with shape a and scale c.