Sleipnir C++ API
Loading...
Searching...
No Matches
regularization_limits.hpp
1// Copyright (c) Sleipnir contributors
2
3#pragma once
4
5#include <algorithm>
6#include <cmath>
7#include <limits>
8
9namespace slp {
10
15template <typename Scalar>
16Scalar min_hessian_regularization() {
17 using std::sqrt;
18
19 // This value keeps regularized pivots well above the near-singular pivot
20 // threshold
21 return sqrt(std::numeric_limits<Scalar>::epsilon()) / Scalar(100);
22}
23
28template <typename Scalar>
29Scalar min_constraint_regularization() {
30 using std::sqrt;
31
32 // γ is bounded on both sides:
33 //
34 // * From below by rounding. A dual pivot is −γ − aᵀD⁻¹a, where a is the
35 // constraint's row of the Jacobian, so γ smaller than the rounding error
36 // in aᵀD⁻¹a has no effect. Below about 100ε in double, nearly dependent
37 // constraints produce exact zero pivots.
38 // * From above by the distortion of the equality constraint Jacobian,
39 // which degrades steps once γ is around 1e-7 to 1e-6 regardless of
40 // Scalar.
41 //
42 // The upper bound doesn't scale with ε, so the window is narrow for float
43 // (about 0.25ε to 2.5ε) and wide for double (about 100ε to 1e-8). This value
44 // falls inside both windows.
45 return sqrt(std::numeric_limits<Scalar>::epsilon()) / Scalar(3000);
46}
47
53template <typename Scalar>
54Scalar near_singular_pivot_threshold() {
55 using std::min;
56
57 // The threshold must be below the regularized pivots, or the regularization
58 // can never fix the inertia. For float, ε exceeds the minimum constraint
59 // regularization.
60 return min(std::numeric_limits<Scalar>::epsilon(),
61 min_constraint_regularization<Scalar>() / Scalar(100));
62}
63
68template <typename Scalar>
69Scalar max_constraint_regularization() {
70 using std::sqrt;
71
72 // Larger values than this distort the equality constraint Jacobian more than
73 // they help a rank-deficient one
74 return sqrt(std::numeric_limits<Scalar>::epsilon());
75}
76
77} // namespace slp