Visual Servoing Platform  version 3.4.0
vpRobust.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * M-Estimator and various influence function.
33  *
34  * Authors:
35  * Andrew Comport
36  * Jean Laneurit
37  *
38  *****************************************************************************/
39 
44 #ifndef vpRobust_h
45 #define vpRobust_h
46 
47 #include <visp3/core/vpConfig.h>
48 #include <visp3/core/vpColVector.h>
49 #include <visp3/core/vpMath.h>
50 
88 class VISP_EXPORT vpRobust
89 {
90 public:
92  typedef enum {
95  HUBER
97 
98 private:
100  vpColVector m_normres;
102  vpColVector m_sorted_normres;
104  vpColVector m_sorted_residues;
105 
107  double m_mad_min;
109  double m_mad_prev;
110 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
111  unsigned int m_iter;
113 #endif
114  unsigned int m_size;
117  double m_mad;
118 
119 public:
120  vpRobust();
121  vpRobust(const vpRobust &other);
122 
124  virtual ~vpRobust(){};
125 
135  double getMedianAbsoluteDeviation() {return m_mad;};
136 
143  double getMinMedianAbsoluteDeviation() {return m_mad_min;};
144 
145  void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, vpColVector &weights);
146 
147  vpRobust &operator=(const vpRobust &other);
148 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
149  vpRobust &operator=(const vpRobust &&other);
150 #endif
151 
161  inline void setMinMedianAbsoluteDeviation(double mad_min) { m_mad_min = mad_min; }
162 
163 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
164 
168  vp_deprecated explicit vpRobust(unsigned int n_data);
170  void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, const vpColVector &all_residues,
171  vpColVector &weights);
176  vp_deprecated void setIteration(unsigned int iter) { m_iter = iter; }
185  vp_deprecated inline void setThreshold(double mad_min) { m_mad_min = mad_min; }
186  vp_deprecated vpColVector simultMEstimator(vpColVector &residues);
188 #endif
189 private:
191  void resize(unsigned int n_data);
192 
193  //---------------------------------
194  // Partial derivative of loss function with respect to the residue
195  //---------------------------------
198  void psiTukey(double sigma, const vpColVector &x, vpColVector &w);
201  void psiCauchy(double sigma, const vpColVector &x, vpColVector &w);
203  void psiHuber(double sigma, const vpColVector &x, vpColVector &w);
205 
206 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
207  double computeNormalizedMedian(vpColVector &all_normres, const vpColVector &residues,
208  const vpColVector &all_residues, const vpColVector &weights);
210  double simultscale(const vpColVector &x);
212  double simult_chi_huber(double x);
213 
214  //---------------------------------
215  // Constrained Partial derivative of loss function with respect to the scale
216  //---------------------------------
219  double constrainedChi(vpRobustEstimatorType method, double x);
222  double constrainedChiTukey(double x);
224  double constrainedChiCauchy(double x);
226  double constrainedChiHuber(double x);
228 
229 #if !defined(VISP_HAVE_FUNC_ERFC) && !defined(VISP_HAVE_FUNC_STD_ERFC)
230  //---------------------------------
231  // Mathematic functions used to calculate the Expectation
232  //---------------------------------
235  vp_deprecated double erf(double x);
236  vp_deprecated double gammp(double a, double x);
237  vp_deprecated void gser(double *gamser, double a, double x, double *gln);
238  vp_deprecated void gcf(double *gammcf, double a, double x, double *gln);
239  vp_deprecated double gammln(double xx);
241 #endif
242 #endif
243 
246  int partition(vpColVector &a, unsigned int l, unsigned int r);
249  double select(vpColVector &a, unsigned int l, unsigned int r, unsigned int k);
251 };
252 
253 #endif
virtual ~vpRobust()
Destructor.
Definition: vpRobust.h:124
double getMinMedianAbsoluteDeviation()
Definition: vpRobust.h:143
vp_deprecated void setIteration(unsigned int iter)
Definition: vpRobust.h:176
vp_deprecated void setThreshold(double mad_min)
Definition: vpRobust.h:185
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
double getMedianAbsoluteDeviation()
Definition: vpRobust.h:135
Contains an M-estimator and various influence function.
Definition: vpRobust.h:88
Tukey influence function.
Definition: vpRobust.h:93
Cauchy influence function.
Definition: vpRobust.h:94
void setMinMedianAbsoluteDeviation(double mad_min)
Definition: vpRobust.h:161
vpRobustEstimatorType
Enumeration of influence functions.
Definition: vpRobust.h:92