MROB
optimizer.hpp
1 /* Copyright (c) 2022, Gonzalo Ferrer
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  *
16  * optimizer.hpp
17  *
18  * Created on: Jul 4, 2020
19  * Author: Gonzalo Ferrer
20  * g.ferrer@skoltech.ru
21  * Mobile Robotics Lab, Skoltech
22  */
23 
24 #ifndef OPTIMIZER_HPP_
25 #define OPTIMIZER_HPP_
26 
27 #include "mrob/matrix_base.hpp"
28 
29 namespace mrob{
30 
53 class Optimizer
54 {
55 public:
62  enum optimMethod{NEWTON_RAPHSON=0, LEVENBERG_MARQUARDT_SPHER, LEVENBERG_MARQUARDT_ELLIP};
63  Optimizer(matData_t solutionTolerance = 1e-4, matData_t lambda = 1e-5);
64  virtual ~Optimizer();
65 
73  uint_t solve(optimMethod method, uint_t max_iters = 1e2, double lambda = 1e-5);
74 
79  virtual matData_t calculate_error() = 0;
89  virtual void calculate_gradient_hessian() = 0;
93  virtual void update_state() = 0;
99  virtual void bookkeep_state() = 0;
104  virtual void update_state_from_bookkeep() = 0;
105 
106 protected:
107 
116  uint_t optimize_newton_raphson();
117 
121  virtual uint_t optimize_newton_raphson_one_iteration(bool useLambda = false) = 0;
122 
130 
138  virtual matData_t calculate_model_fidelity(matData_t diff_error) = 0;
139 
140 
141  optimMethod optimization_method_ {};
142  matData_t solutionTolerance_;
143  uint_t max_iters_;
144  MatX1 gradient_, dx_;
145 
146  // Necessary for LM, Other LM parameters are set to default (see .cpp)
147  matData_t lambda_;
148 
149 };
150 
151 class OptimizerDense : public Optimizer
152 {
153  public:
154  OptimizerDense(matData_t solutionTolerance = 1e-4, matData_t lambda = 1e-5);
155  virtual ~OptimizerDense();
156  protected:
157  uint_t optimize_newton_raphson_one_iteration(bool useLambda = false);
158  matData_t calculate_model_fidelity(matData_t diff_error);
159  MatX hessian_;
160 };
161 
162 
164 {
165  protected:
166  MatX hessian_;
167 };
168 
169 
170 }
171 #endif /* SRC_COMMON_MROB_OPTIMIZER_HPP_ */
Definition: optimizer.hpp:151
virtual void update_state()=0
virtual void update_state_from_bookkeep()=0
optimMethod
Definition: optimizer.hpp:62
virtual void calculate_gradient_hessian()=0
uint_t solve(optimMethod method, uint_t max_iters=1e2, double lambda=1e-5)
Definition: optimizer.cpp:42
Definition: optimizer.hpp:53
virtual uint_t optimize_newton_raphson_one_iteration(bool useLambda=false)=0
uint_t optimize_newton_raphson()
Definition: optimizer.cpp:85
Definition: optimizer.hpp:163
Special Euclidean (group) in 3d Is the group representing rotations and translations, that is, rigid body transformations. SE3 = {T = [R t] | R SO3 , t Re^3 } [0 1] Associated to the groups of RBT, there is the Lie algebra se3 representing the same transformation in the tangent space around the identity. Particularly, xi =[w , v] Re^6, where w Re^3 represents the rotation and v the translation. We will preserve this order in this class.
Definition: matrix_base.hpp:36
virtual matData_t calculate_model_fidelity(matData_t diff_error)=0
virtual void bookkeep_state()=0
uint_t optimize_levenberg_marquardt()
Definition: optimizer.cpp:104
virtual matData_t calculate_error()=0