Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpRobust.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * M-Estimator and various influence function.
32  *
33  * Authors:
34  * Andrew Comport
35  * Jean Laneurit
36  *
37  *****************************************************************************/
38 
45 #ifndef CROBUST_HH
46 #define CROBUST_HH
47 
48 #include <visp3/core/vpConfig.h>
49 #include <visp3/core/vpColVector.h>
50 #include <visp3/core/vpMath.h>
51 
52 
60 class VISP_EXPORT vpRobust
61 {
62 
63 public:
65  typedef enum
66  {
69  // MCLURE,
70  HUBER
71  } vpRobustEstimatorType;
72 
73 private:
74 
76  vpColVector normres;
78  vpColVector sorted_normres;
80  vpColVector sorted_residues;
81 
83  double NoiseThreshold;
85  double sig_prev;
87  unsigned int it;
89  double swap;
91  unsigned int size;
92 
93 public:
94 
96  vpRobust(unsigned int n_data);
97  vpRobust();
98  vpRobust(const vpRobust &other);
99 
101  virtual ~vpRobust(){};
102 
104  void MEstimator(const vpRobustEstimatorType method,
105  const vpColVector &residues,
106  vpColVector &weights);
107 
109  void MEstimator(const vpRobustEstimatorType method,
110  const vpColVector &residues,
111  const vpColVector& all_residues,
112  vpColVector &weights);
113 
114  vpRobust & operator=(const vpRobust &other);
115 #ifdef VISP_HAVE_CPP11_COMPATIBILITY
116  vpRobust & operator=(const vpRobust &&other);
117 #endif
118 
120  void resize(unsigned int n_data);
121 
123  void setIteration(const unsigned int iter){it=iter;}
124 
129  inline void setThreshold(const double noise_threshold) {
130  NoiseThreshold=noise_threshold;
131  }
132 
134  vpColVector simultMEstimator(vpColVector &residues);
135 
136 //public :
137 //double residualMedian ;
138 //double normalizedResidualMedian ;
139 // private:
140 // double median(const vpColVector &x);
141 // double median(const vpColVector &x, vpColVector &weights);
142 
143  private:
145  double computeNormalizedMedian(vpColVector &all_normres,
146  const vpColVector &residues,
147  const vpColVector &all_residues,
148  const vpColVector &weights
149  );
150 
151 
153  double scale(vpRobustEstimatorType method, vpColVector &x);
154  double simultscale(vpColVector &x);
155 
156 
157  //---------------------------------
158  // Partial derivative of loss function with respect to the residue
159  //---------------------------------
162  void psiTukey(double sigma, vpColVector &x, vpColVector &w);
165  void psiCauchy(double sigma, vpColVector &x, vpColVector &w);
167  void psiMcLure(double sigma, vpColVector &x, vpColVector &w);
169  void psiHuber(double sigma, vpColVector &x, vpColVector &w);
171 
174  double simult_chi_huber(double x);
175 
176  //---------------------------------
177  // Constrained Partial derivative of loss function with respect to the scale
178  //---------------------------------
181  double constrainedChi(vpRobustEstimatorType method, double x);
184  double constrainedChiTukey(double x);
186  double constrainedChiCauchy(double x);
188  double constrainedChiHuber(double x);
190 
191 #if !defined(VISP_HAVE_FUNC_ERFC) && !defined(VISP_HAVE_FUNC_STD_ERFC)
192  //---------------------------------
193  // Mathematic functions used to calculate the Expectation
194  //---------------------------------
197  double erf(double x);
198  double gammp(double a, double x);
199  void gser(double *gamser, double a, double x, double *gln);
200  void gcf(double *gammcf, double a, double x, double *gln);
201  double gammln(double xx);
203 #endif
204 
207  void exch(double &A, double &B){swap = A; A = B; B = swap;}
210  int partition(vpColVector &a, int l, int r);
212  double select(vpColVector &a, int l, int r, int k);
214 };
215 
216 #endif
virtual ~vpRobust()
Destructor.
Definition: vpRobust.h:101
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
Contains an M-Estimator and various influence function.
Definition: vpRobust.h:60
void setThreshold(const double noise_threshold)
Definition: vpRobust.h:129
void setIteration(const unsigned int iter)
Set iteration.
Definition: vpRobust.h:123