Main MRPT website > C++ reference for MRPT 1.5.6
robust_kernels_unittest.cpp
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 
12 #include <gtest/gtest.h>
13 
14 using namespace mrpt;
15 using namespace mrpt::math;
16 using namespace std;
17 
18 // Test data tables:
19 // Lists of: E2 (squared error) ; PARAM2 (squared kernel parameter) ; R2 (expected robustified output) ; R' (1st derivative) ; R'' (2nd derivative)
20 // ============= Kernel: None (plain least squares)
21 const double list_test_kernel_none[][5] = {
22  { 0.0 , .0 , 0.0 , 1.0 , 0.0 },
23  { 1.0 , .0 , 1.0 , 1.0 , 0.0 },
24  { 10.0 , .0 , 10.0 , 1.0 , 0.0 }
25 };
26 
27 // ============= Kernel: Pseudo-Huber
28 const double list_test_kernel_pshb[][5] = {
29  { 0.0 , 1.0 , 0.0 , 1.0 ,-0.5 },
30  { 0.0 , 4.0 , 0.0 , 1.0 ,-0.125 },
31  { 0.0 , 9.0 , 0.0 , 1.0 ,-0.0555556 },
32  { 1.0 , 1.0 , 0.828427 , 0.707107 ,-0.176777 },
33  { 1.0 , 4.0 , 0.944272 , 0.894427 ,-0.0894427 },
34  { 1.0 , 9.0 , 0.973666 , 0.948683 ,-0.0474342 },
35  { 4.0 , 1.0 , 2.47214 , 0.447214 ,-0.0447214 },
36  { 4.0 , 4.0 , 3.31371 , 0.707107 ,-0.0441942 },
37  { 4.0 , 9.0 , 3.63331 , 0.83205 ,-0.0320019 }
38 };
39 
40 template <TRobustKernelType KERNEL_TYPE>
41 void tester_robust_kernel(const double table[][5], const size_t N)
42 {
44 
45  for (size_t i=0;i<N;i++)
46  {
47  const double e2 = table[i][0];
48  const double param2 = table[i][1];
49 
50  double rhop, rhopp;
51  rKernel.param_sq = param2;
52  double r2 = rKernel.eval(e2,rhop,rhopp);
53 
54  const double expected_r2 = table[i][2];
55  const double expected_rhop = table[i][3];
56  const double expected_rhopp = table[i][4];
57 
58  EXPECT_NEAR(r2,expected_r2,1e-5);
59  EXPECT_NEAR(rhop,expected_rhop,1e-5);
60  EXPECT_NEAR(rhopp,expected_rhopp,1e-5);
61  }
62 }
63 
64 TEST(RobustKernels,PlainLeastSquares)
65 {
66  const size_t N = sizeof(list_test_kernel_none)/sizeof(list_test_kernel_none[0]);
67  tester_robust_kernel<rkLeastSquares>(list_test_kernel_none, N);
68 }
69 
70 TEST(RobustKernels,PseudoHuber)
71 {
72  const size_t N = sizeof(list_test_kernel_pshb)/sizeof(list_test_kernel_pshb[0]);
73  tester_robust_kernel<rkPseudoHuber>(list_test_kernel_pshb, N);
74 }
75 
76 
77 
const double list_test_kernel_pshb[][5]
GLenum GLsizei GLenum GLenum const GLvoid * table
Definition: glext.h:3513
STL namespace.
void tester_robust_kernel(const double table[][5], const size_t N)
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
const double list_test_kernel_none[][5]
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
TEST(RobustKernels, PlainLeastSquares)



Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019