Main MRPT website > C++ reference for MRPT 1.9.9
robust_kernels.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #ifndef mrpt_robust_kernels_H
11 #define mrpt_robust_kernels_H
12 
13 #include <mrpt/utils/types.h>
14 
15 namespace mrpt
16 {
17 namespace math
18 {
19 /** \addtogroup mrpt_base_grp
20  * @{ */
21 
22 /** The different types of kernels for usage within a robustified least-squares
23  * estimator.
24  * \sa Use these types as arguments of the template RobustKernel<>
25  */
27 {
28  /** No robust kernel, use standard least squares: rho(r)= 1/2 * r^2 */
30  /** Pseudo-huber robust kernel */
32 };
33 
34 // Generic declaration.
35 template <TRobustKernelType KERNEL_TYPE, typename T = double>
36 struct RobustKernel;
37 
38 /** No robust kernel, use standard least squares: rho(r) = r^2 */
39 template <typename T>
41 {
42  /** The kernel parameter (the "threshold") squared [Not used in this class,
43  * provided for consistency with the other classes] */
45 
46  /** Evaluates the kernel function for the squared error r2 and returns
47  * robustified squared error and derivatives of sqrt(2*rho(r)) at this
48  * point. */
49  inline T eval(const T r2, T& out_1st_deriv, T& out_2nd_deriv)
50  {
51  out_1st_deriv = 1;
52  out_2nd_deriv = 0;
53  return r2; // return: 2*cost; cost: 0.5* |r|^2
54  }
55 };
56 
57 /** Pseudo-huber robust kernel: rho(r) = 2 * delta^2 * ( -1+sqrt( 1+
58  * r^2/delta^2 ) ) */
59 template <typename T>
61 {
62  /** The kernel parameter (the "threshold") squared. */
64 
65  /** Evaluates the kernel function for the squared error r2 and returns
66  * robustified squared error and derivatives of sqrt(2*rho(r)) at this
67  * point. */
68  inline T eval(const T r2, T& out_1st_deriv, T& out_2nd_deriv)
69  {
70  const T param_sq_inv = 1.0 / param_sq;
71  const T a = 1 + r2 * param_sq_inv;
72  const T b = std::sqrt(a);
73  out_1st_deriv = 1. / b;
74  out_2nd_deriv = -0.5 * param_sq_inv * out_1st_deriv / a;
75  return 2 * param_sq * (b - 1);
76  ; // return: 2*cost
77  }
78 };
79 
80 /** @} */ // end of grouping
81 }
82 }
83 
84 #endif
T eval(const T r2, T &out_1st_deriv, T &out_2nd_deriv)
Evaluates the kernel function for the squared error r2 and returns robustified squared error and deri...
T param_sq
The kernel parameter (the "threshold") squared [Not used in this class, provided for consistency with...
Pseudo-huber robust kernel.
T eval(const T r2, T &out_1st_deriv, T &out_2nd_deriv)
Evaluates the kernel function for the squared error r2 and returns robustified squared error and deri...
No robust kernel, use standard least squares: rho(r)= 1/2 * r^2.
TRobustKernelType
The different types of kernels for usage within a robustified least-squares estimator.
GLubyte GLubyte b
Definition: glext.h:6279
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
T param_sq
The kernel parameter (the "threshold") squared.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019