Visual Servoing Platform  version 3.6.1 under development (2023-10-03)
vpRobust.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
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 https://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 
38 #ifndef vpRobust_h
39 #define vpRobust_h
40 
41 #include <visp3/core/vpColVector.h>
42 #include <visp3/core/vpConfig.h>
43 #include <visp3/core/vpMath.h>
44 
82 class VISP_EXPORT vpRobust
83 {
84 public:
86  typedef enum {
89  HUBER
90  } vpRobustEstimatorType;
91 
92 private:
94  vpColVector m_normres;
96  vpColVector m_sorted_normres;
98  vpColVector m_sorted_residues;
99 
101  double m_mad_min;
103  double m_mad_prev;
104 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
106  unsigned int m_iter;
107 #endif
109  unsigned int m_size;
111  double m_mad;
112 
113 public:
114  vpRobust();
115  vpRobust(const vpRobust &other);
116 
118  virtual ~vpRobust(){};
119 
129  double getMedianAbsoluteDeviation() { return m_mad; };
130 
137  double getMinMedianAbsoluteDeviation() { return m_mad_min; };
138 
139  void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, vpColVector &weights);
140 
141  vpRobust &operator=(const vpRobust &other);
142 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
143  vpRobust &operator=(const vpRobust &&other);
144 #endif
145 
155  inline void setMinMedianAbsoluteDeviation(double mad_min) { m_mad_min = mad_min; }
156 
157 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
162  vp_deprecated explicit vpRobust(unsigned int n_data);
164  void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, const vpColVector &all_residues,
165  vpColVector &weights);
170  vp_deprecated void setIteration(unsigned int iter) { m_iter = iter; }
179  vp_deprecated inline void setThreshold(double mad_min) { m_mad_min = mad_min; }
180  vp_deprecated vpColVector simultMEstimator(vpColVector &residues);
182 #endif
183 private:
185  void resize(unsigned int n_data);
186 
187  //---------------------------------
188  // Partial derivative of loss function with respect to the residue
189  //---------------------------------
192  void psiTukey(double sigma, const vpColVector &x, vpColVector &w);
195  void psiCauchy(double sigma, const vpColVector &x, vpColVector &w);
197  void psiHuber(double sigma, const vpColVector &x, vpColVector &w);
199 
200 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
201  double computeNormalizedMedian(vpColVector &all_normres, const vpColVector &residues, const vpColVector &all_residues,
202  const vpColVector &weights);
204  double simultscale(const vpColVector &x);
206  double simult_chi_huber(double x);
207 
208  //---------------------------------
209  // Constrained Partial derivative of loss function with respect to the scale
210  //---------------------------------
213  double constrainedChi(vpRobustEstimatorType method, double x);
216  double constrainedChiTukey(double x);
218  double constrainedChiCauchy(double x);
220  double constrainedChiHuber(double x);
222 
223 #if !defined(VISP_HAVE_FUNC_ERFC) && !defined(VISP_HAVE_FUNC_STD_ERFC)
224  //---------------------------------
225  // Mathematic functions used to calculate the Expectation
226  //---------------------------------
229  double erf(double x);
230  double gammp(double a, double x);
231  void gser(double *gamser, double a, double x, double *gln);
232  void gcf(double *gammcf, double a, double x, double *gln);
233  double gammln(double xx);
235 #endif
236 #endif
237 
241  int partition(vpColVector &a, int l, int r);
243  double select(vpColVector &a, int l, int r, int k);
245 };
246 
247 #endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:167
Contains an M-estimator and various influence function.
Definition: vpRobust.h:83
@ TUKEY
Tukey influence function.
Definition: vpRobust.h:87
@ CAUCHY
Cauchy influence function.
Definition: vpRobust.h:88
void setMinMedianAbsoluteDeviation(double mad_min)
Definition: vpRobust.h:155
vp_deprecated void setThreshold(double mad_min)
Definition: vpRobust.h:179
double getMedianAbsoluteDeviation()
Definition: vpRobust.h:129
double getMinMedianAbsoluteDeviation()
Definition: vpRobust.h:137
virtual ~vpRobust()
Destructor.
Definition: vpRobust.h:118
vp_deprecated void setIteration(unsigned int iter)
Definition: vpRobust.h:170