Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
vpRobust.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 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 VP_ROBUST_H
39 #define VP_ROBUST_H
40 
41 #include <visp3/core/vpConfig.h>
42 #include <visp3/core/vpColVector.h>
43 #include <visp3/core/vpMath.h>
44 
83 class VISP_EXPORT vpRobust
84 {
85 public:
87  typedef enum
88  {
91  HUBER
92  } vpRobustEstimatorType;
93 
94 public:
95  vpRobust();
96  vpRobust(const vpRobust &other);
97 
99  virtual ~vpRobust() { };
100 
110  double getMedianAbsoluteDeviation() { return m_mad; };
111 
118  double getMinMedianAbsoluteDeviation() { return m_mad_min; };
119 
120  void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, vpColVector &weights);
121 
122  vpRobust &operator=(const vpRobust &other);
123 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
124  vpRobust &operator=(const vpRobust &&other);
125 #endif
126 
136  inline void setMinMedianAbsoluteDeviation(double mad_min) { m_mad_min = mad_min; }
137 
138 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
143  VP_DEPRECATED VP_EXPLICIT vpRobust(unsigned int n_data);
145  void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, const vpColVector &all_residues,
146  vpColVector &weights);
151  VP_DEPRECATED void setIteration(unsigned int iter) { m_iter = iter; }
160  VP_DEPRECATED inline void setThreshold(double mad_min) { m_mad_min = mad_min; }
161  VP_DEPRECATED vpColVector simultMEstimator(vpColVector &residues);
163 #endif
164 private:
166  vpColVector m_normres;
168  vpColVector m_sorted_normres;
170  vpColVector m_sorted_residues;
171 
173  double m_mad_min;
175  double m_mad_prev;
176 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
178  unsigned int m_iter;
179 #endif
181  unsigned int m_size;
183  double m_mad;
184 
185 private:
187  void resize(unsigned int n_data);
188 
189  //---------------------------------
190  // Partial derivative of loss function with respect to the residue
191  //---------------------------------
194  void psiTukey(double sigma, const vpColVector &x, vpColVector &w);
197  void psiCauchy(double sigma, const vpColVector &x, vpColVector &w);
199  void psiHuber(double sigma, const vpColVector &x, vpColVector &w);
201 
202 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
203  double computeNormalizedMedian(vpColVector &all_normres, const vpColVector &residues, const vpColVector &all_residues,
204  const vpColVector &weights);
206  double simultscale(const vpColVector &x);
208  double simult_chi_huber(double x);
209 
210  //---------------------------------
211  // Constrained Partial derivative of loss function with respect to the scale
212  //---------------------------------
215  double constrainedChi(vpRobustEstimatorType method, double x);
218  double constrainedChiTukey(double x);
220  double constrainedChiCauchy(double x);
222  double constrainedChiHuber(double x);
224 
225 #if !defined(VISP_HAVE_FUNC_ERFC) && !defined(VISP_HAVE_FUNC_STD_ERFC)
226  //---------------------------------
227  // Mathematic functions used to calculate the Expectation
228  //---------------------------------
231  double erf(double x);
232  double gammp(double a, double x);
233  void gser(double *gamser, double a, double x, double *gln);
234  void gcf(double *gammcf, double a, double x, double *gln);
235  double gammln(double xx);
237 #endif
238 #endif
239 
243  int partition(vpColVector &a, int l, int r);
245  double select(vpColVector &a, int l, int r, int k);
247 };
248 END_VISP_NAMESPACE
249 #endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
Contains an M-estimator and various influence function.
Definition: vpRobust.h:84
VP_DEPRECATED void setIteration(unsigned int iter)
Definition: vpRobust.h:151
VP_DEPRECATED void setThreshold(double mad_min)
Definition: vpRobust.h:160
@ TUKEY
Tukey influence function.
Definition: vpRobust.h:89
@ CAUCHY
Cauchy influence function.
Definition: vpRobust.h:90
void setMinMedianAbsoluteDeviation(double mad_min)
Definition: vpRobust.h:136
double getMedianAbsoluteDeviation()
Definition: vpRobust.h:110
double getMinMedianAbsoluteDeviation()
Definition: vpRobust.h:118
virtual ~vpRobust()
Destructor.
Definition: vpRobust.h:99