43 #include <visp3/core/vpConfig.h>
44 #include <visp3/core/vpGaussRand.h>
45 #include <visp3/core/vpRobust.h>
46 #include <visp3/mbt/vpMbtTukeyEstimator.h>
50 #ifdef ENABLE_VISP_NAMESPACE
53 size_t nb_elements = 1000;
54 int nb_iterations = 100;
55 double stdev = 0.5, mean = 0.0, noise_threshold = 1e-3;
58 noise.seed((
unsigned int)time(
nullptr));
60 vpColVector residues_col((
unsigned int)nb_elements);
62 for (
size_t i = 0; i < nb_elements; i++) {
63 residues_col[(
unsigned int)i] = noise();
69 for (
int i = 0; i < nb_iterations; i++) {
74 vpMbtTukeyEstimator<double> tukey_estimator;
75 std::vector<double> residues(nb_elements);
76 for (
size_t i = 0; i < residues.size(); i++) {
77 residues[i] = residues_col[(
unsigned int)i];
80 std::vector<double> weights;
82 for (
int i = 0; i < nb_iterations; i++) {
83 tukey_estimator.MEstimator(residues, weights, noise_threshold);
87 std::cout <<
"t_robust=" << t_robust <<
" ms ; t (double)=" << t <<
" ; ratio=" << (t_robust / t) << std::endl;
89 for (
size_t i = 0; i < weights.size(); i++) {
90 if (!
vpMath::equal(weights[i], weights_col[(
unsigned int)i], noise_threshold)) {
91 std::cerr <<
"Difference between vpRobust::TUKEY and "
92 "vpMbtTukeyEstimator (double)!"
94 std::cerr <<
"weights_col[" << i <<
"]=" << weights_col[(
unsigned int)i] << std::endl;
95 std::cerr <<
"weights[" << i <<
"]=" << weights[i] << std::endl;
102 for (
size_t i = 0; i < nb_elements; i++) {
103 residues_col[(
unsigned int)i] = noise();
105 weights_col_save = weights_col;
107 for (
int i = 0; i < nb_iterations; i++) {
113 vpMbtTukeyEstimator<float> tukey_estimator;
114 std::vector<float> residues(nb_elements);
115 std::vector<float> weights(nb_elements);
116 for (
size_t i = 0; i < residues.size(); i++) {
117 residues[i] = (float)residues_col[(
unsigned int)i];
118 weights[i] = (float)weights_col_save[(
unsigned int)i];
122 for (
int i = 0; i < nb_iterations; i++) {
123 tukey_estimator.MEstimator(residues, weights, (
float)noise_threshold);
127 std::cout <<
"t_robust=" << t_robust <<
" ms ; t (float)=" << t <<
" ; ratio=" << (t_robust / t) << std::endl;
129 for (
size_t i = 0; i < weights.size(); i++) {
130 if (!
vpMath::equal(weights[i], weights_col[(
unsigned int)i], noise_threshold)) {
131 std::cerr <<
"Difference between vpRobust::TUKEY and "
132 "vpMbtTukeyEstimator (float)!"
134 std::cerr <<
"weights_col[" << i <<
"]=" << weights_col[(
unsigned int)i] << std::endl;
135 std::cerr <<
"weights[" << i <<
"]=" << weights[i] << std::endl;
142 for (
size_t i = 0; i < nb_elements; i++) {
143 residues_col[(
unsigned int)i] = noise();
145 weights_col_save = weights_col;
147 for (
int i = 0; i < nb_iterations; i++) {
153 vpMbtTukeyEstimator<double> tukey_estimator;
158 for (
int i = 0; i < nb_iterations; i++) {
159 tukey_estimator.MEstimator(residues, weights, noise_threshold);
163 std::cout <<
"t_robust=" << t_robust <<
" ms ; t (vpColVector)=" << t <<
" ; ratio=" << (t_robust / t) << std::endl;
165 for (
size_t i = 0; i < weights.
size(); i++) {
166 if (!
vpMath::equal(weights[(
unsigned int)i], weights_col[(
unsigned int)i], noise_threshold)) {
167 std::cerr <<
"Difference between vpRobust::TUKEY and "
168 "vpMbtTukeyEstimator (float)!"
170 std::cerr <<
"weights_col[" << i <<
"]=" << weights_col[(
unsigned int)i] << std::endl;
171 std::cerr <<
"weights[" << i <<
"]=" << weights[(
unsigned int)i] << std::endl;
177 std::cout <<
"vpMbtTukeyEstimator returns the same values than vpRobust::TUKEY." << std::endl;
unsigned int size() const
Return the number of elements of the 2D array.
Implementation of column vector and the associated operations.
Class for generating random number with normal probability density.
static bool equal(double x, double y, double threshold=0.001)
Contains an M-estimator and various influence function.
@ TUKEY
Tukey influence function.
void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, vpColVector &weights)
void setMinMedianAbsoluteDeviation(double mad_min)
VISP_EXPORT double measureTimeMs()