Visual Servoing Platform  version 3.0.0
vpRobust.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 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/vpColVector.h>
49 #include <visp3/core/vpMath.h>
50 
51 
59 class VISP_EXPORT vpRobust
60 {
61 
62 public:
64  typedef enum
65  {
68  // MCLURE,
69  HUBER
70  } vpRobustEstimatorType;
71 
72 private:
73 
75  vpColVector normres;
77  vpColVector sorted_normres;
79  vpColVector sorted_residues;
80 
82  double NoiseThreshold;
84  double sig_prev;
86  unsigned int it;
88  double swap;
90  unsigned int size;
91 
92 public:
93 
95  vpRobust(unsigned int n_data);
96 
98  virtual ~vpRobust(){};
99 
101  void resize(unsigned int n_data);
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 
115  vpColVector simultMEstimator(vpColVector &residues);
116 
118  void setIteration(const unsigned int iter){it=iter;}
119 
124  inline void setThreshold(const double noise_threshold) {
125  NoiseThreshold=noise_threshold;
126  }
127 
128 //public :
129 //double residualMedian ;
130 //double normalizedResidualMedian ;
131 // private:
132 // double median(const vpColVector &x);
133 // double median(const vpColVector &x, vpColVector &weights);
134 
135  private:
137  double computeNormalizedMedian(vpColVector &all_normres,
138  const vpColVector &residues,
139  const vpColVector &all_residues,
140  const vpColVector &weights
141  );
142 
143 
145  double scale(vpRobustEstimatorType method, vpColVector &x);
146  double simultscale(vpColVector &x);
147 
148 
149  //---------------------------------
150  // Partial derivative of loss function with respect to the residue
151  //---------------------------------
154  void psiTukey(double sigma, vpColVector &x, vpColVector &w);
157  void psiCauchy(double sigma, vpColVector &x, vpColVector &w);
159  void psiMcLure(double sigma, vpColVector &x, vpColVector &w);
161  void psiHuber(double sigma, vpColVector &x, vpColVector &w);
163 
166  double simult_chi_huber(double x);
167 
168  //---------------------------------
169  // Constrained Partial derivative of loss function with respect to the scale
170  //---------------------------------
173  double constrainedChi(vpRobustEstimatorType method, double x);
176  double constrainedChiTukey(double x);
178  double constrainedChiCauchy(double x);
180  double constrainedChiHuber(double x);
182 
183  //---------------------------------
184  // Mathematic functions used to calculate the Expectation
185  //---------------------------------
188  double erf(double x);
189  double gammp(double a, double x);
190  void gser(double *gamser, double a, double x, double *gln);
191  void gcf(double *gammcf, double a, double x, double *gln);
192  double gammln(double xx);
194 
197  void exch(double &A, double &B){swap = A; A = B; B = swap;}
200  int partition(vpColVector &a, int l, int r);
202  double select(vpColVector &a, int l, int r, int k);
204 };
205 
206 #endif
virtual ~vpRobust()
Destructor.
Definition: vpRobust.h:98
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
Contains an M-Estimator and various influence function.
Definition: vpRobust.h:59
void setThreshold(const double noise_threshold)
Definition: vpRobust.h:124
void setIteration(const unsigned int iter)
Set iteration.
Definition: vpRobust.h:118