Directory: | ./ |
---|---|
File: | include/pinocchio/algorithm/proximal.hpp |
Date: | 2024-08-27 18:20:05 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 21 | 33 | 63.6% |
Branches: | 7 | 44 | 15.9% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2019-2022 INRIA | ||
3 | // | ||
4 | |||
5 | #ifndef __pinocchio_algorithm_proximal_hpp__ | ||
6 | #define __pinocchio_algorithm_proximal_hpp__ | ||
7 | |||
8 | #include <Eigen/Core> | ||
9 | #include "pinocchio/multibody/model.hpp" | ||
10 | #include "pinocchio/multibody/data.hpp" | ||
11 | |||
12 | namespace pinocchio | ||
13 | { | ||
14 | |||
15 | /// | ||
16 | /// \brief Structure containing all the settings parameters for the proximal algorithms. | ||
17 | /// | ||
18 | /// \tparam _Scalar Scalar type of the for the regularization and the accuracy parameter. | ||
19 | /// | ||
20 | /// It contains the accuracy, the maximal number of iterations and the regularization factor | ||
21 | /// common to all proximal algorithms. | ||
22 | /// | ||
23 | template<typename _Scalar> | ||
24 | struct ProximalSettingsTpl | ||
25 | { | ||
26 | typedef _Scalar Scalar; | ||
27 | |||
28 | /// \brief Default constructor. | ||
29 | 69 | ProximalSettingsTpl() | |
30 | 69 | : absolute_accuracy(Eigen::NumTraits<Scalar>::dummy_precision()) | |
31 | 69 | , relative_accuracy(Eigen::NumTraits<Scalar>::dummy_precision()) | |
32 | 69 | , mu(0) | |
33 | 69 | , max_iter(1) | |
34 | 69 | , absolute_residual(-1.) | |
35 | 69 | , relative_residual(-1.) | |
36 | 69 | , iter(0) | |
37 | { | ||
38 | 69 | } | |
39 | |||
40 | /// | ||
41 | /// \brief Constructor with all the setting parameters. | ||
42 | /// | ||
43 | 42 | ProximalSettingsTpl(const Scalar accuracy, const Scalar mu, const int max_iter) | |
44 | 42 | : absolute_accuracy(accuracy) | |
45 | 42 | , relative_accuracy(accuracy) | |
46 | 42 | , mu(mu) | |
47 | 42 | , max_iter(max_iter) | |
48 | 42 | , absolute_residual(-1.) | |
49 | 42 | , relative_residual(-1.) | |
50 | 42 | , iter(0) | |
51 | { | ||
52 |
3/8✓ Branch 1 taken 42 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 42 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 42 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
42 | PINOCCHIO_CHECK_INPUT_ARGUMENT( |
53 | check_expression_if_real<Scalar>(accuracy >= 0.) && "Accuracy must be positive."); | ||
54 |
3/8✓ Branch 1 taken 42 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 42 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 42 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
42 | PINOCCHIO_CHECK_INPUT_ARGUMENT( |
55 | check_expression_if_real<Scalar>(mu >= 0.) && "mu must be positive"); | ||
56 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
|
42 | assert(max_iter >= 1 && "max_iter must be greater or equal to 1"); |
57 | 42 | } | |
58 | |||
59 | /// | ||
60 | /// \brief Constructor with all the setting parameters. | ||
61 | /// | ||
62 | ✗ | ProximalSettingsTpl( | |
63 | const Scalar absolute_accuracy, | ||
64 | const Scalar relative_accuracy, | ||
65 | const Scalar mu, | ||
66 | const int max_iter) | ||
67 | ✗ | : absolute_accuracy(absolute_accuracy) | |
68 | ✗ | , relative_accuracy(relative_accuracy) | |
69 | ✗ | , mu(mu) | |
70 | ✗ | , max_iter(max_iter) | |
71 | ✗ | , absolute_residual(-1.) | |
72 | ✗ | , relative_residual(-1.) | |
73 | ✗ | , iter(0) | |
74 | { | ||
75 | ✗ | PINOCCHIO_CHECK_INPUT_ARGUMENT( | |
76 | check_expression_if_real<Scalar>(absolute_accuracy >= 0.) | ||
77 | && "Absolute accuracy must be positive."); | ||
78 | ✗ | PINOCCHIO_CHECK_INPUT_ARGUMENT( | |
79 | check_expression_if_real<Scalar>(relative_accuracy >= 0.) | ||
80 | && "Relative accuracy must be positive."); | ||
81 | ✗ | PINOCCHIO_CHECK_INPUT_ARGUMENT( | |
82 | check_expression_if_real<Scalar>(mu >= 0.) && "mu must be positive"); | ||
83 | ✗ | assert(max_iter >= 1 && "max_iter must be greater or equal to 1"); | |
84 | } | ||
85 | |||
86 | // data | ||
87 | |||
88 | /// \brief Absolute proximal accuracy. | ||
89 | Scalar absolute_accuracy; | ||
90 | |||
91 | /// \brief Relative proximal accuracy between two iterates. | ||
92 | Scalar relative_accuracy; | ||
93 | |||
94 | /// \brief Regularization parameter of the proximal algorithm. | ||
95 | Scalar mu; | ||
96 | |||
97 | /// \brief Maximal number of iterations. | ||
98 | int max_iter; | ||
99 | |||
100 | // data that can be modified by the algorithm | ||
101 | |||
102 | /// \brief Absolute residual. | ||
103 | Scalar absolute_residual; | ||
104 | |||
105 | /// \brief Relatice residual between two iterates. | ||
106 | Scalar relative_residual; | ||
107 | |||
108 | /// \brief Total number of iterations of the algorithm when it has converged or reached the | ||
109 | /// maximal number of allowed iterations. | ||
110 | int iter; | ||
111 | }; | ||
112 | |||
113 | } // namespace pinocchio | ||
114 | |||
115 | #if PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION | ||
116 | #include "pinocchio/algorithm/proximal.txx" | ||
117 | #endif // PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION | ||
118 | |||
119 | #endif // ifndef __pinocchio_algorithm_proximal_hpp__ | ||
120 |