45 #include <visp3/core/vpConfig.h>
46 #include <visp3/core/vpGaussRand.h>
47 #include <visp3/core/vpRobust.h>
48 #include <visp3/mbt/vpMbtTukeyEstimator.h>
52 size_t nb_elements = 1000;
53 int nb_iterations = 100;
54 double stdev = 0.5, mean = 0.0, noise_threshold = 1e-3;
57 noise.seed((
unsigned int)time(
nullptr));
59 vpColVector residues_col((
unsigned int)nb_elements);
61 for (
size_t i = 0; i < nb_elements; i++) {
62 residues_col[(
unsigned int)i] = noise();
68 for (
int i = 0; i < nb_iterations; i++) {
73 vpMbtTukeyEstimator<double> tukey_estimator;
74 std::vector<double> residues(nb_elements);
75 for (
size_t i = 0; i < residues.size(); i++) {
76 residues[i] = residues_col[(
unsigned int)i];
79 std::vector<double> weights;
81 for (
int i = 0; i < nb_iterations; i++) {
82 tukey_estimator.MEstimator(residues, weights, noise_threshold);
86 std::cout <<
"t_robust=" << t_robust <<
" ms ; t (double)=" << t <<
" ; ratio=" << (t_robust / t) << std::endl;
88 for (
size_t i = 0; i < weights.size(); i++) {
89 if (!
vpMath::equal(weights[i], weights_col[(
unsigned int)i], noise_threshold)) {
90 std::cerr <<
"Difference between vpRobust::TUKEY and "
91 "vpMbtTukeyEstimator (double)!"
93 std::cerr <<
"weights_col[" << i <<
"]=" << weights_col[(
unsigned int)i] << std::endl;
94 std::cerr <<
"weights[" << i <<
"]=" << weights[i] << std::endl;
101 for (
size_t i = 0; i < nb_elements; i++) {
102 residues_col[(
unsigned int)i] = noise();
104 weights_col_save = weights_col;
106 for (
int i = 0; i < nb_iterations; i++) {
112 vpMbtTukeyEstimator<float> tukey_estimator;
113 std::vector<float> residues(nb_elements);
114 std::vector<float> weights(nb_elements);
115 for (
size_t i = 0; i < residues.size(); i++) {
116 residues[i] = (float)residues_col[(
unsigned int)i];
117 weights[i] = (float)weights_col_save[(
unsigned int)i];
121 for (
int i = 0; i < nb_iterations; i++) {
122 tukey_estimator.MEstimator(residues, weights, (
float)noise_threshold);
126 std::cout <<
"t_robust=" << t_robust <<
" ms ; t (float)=" << t <<
" ; ratio=" << (t_robust / t) << std::endl;
128 for (
size_t i = 0; i < weights.size(); i++) {
129 if (!
vpMath::equal(weights[i], weights_col[(
unsigned int)i], noise_threshold)) {
130 std::cerr <<
"Difference between vpRobust::TUKEY and "
131 "vpMbtTukeyEstimator (float)!"
133 std::cerr <<
"weights_col[" << i <<
"]=" << weights_col[(
unsigned int)i] << std::endl;
134 std::cerr <<
"weights[" << i <<
"]=" << weights[i] << std::endl;
141 for (
size_t i = 0; i < nb_elements; i++) {
142 residues_col[(
unsigned int)i] = noise();
144 weights_col_save = weights_col;
146 for (
int i = 0; i < nb_iterations; i++) {
152 vpMbtTukeyEstimator<double> tukey_estimator;
157 for (
int i = 0; i < nb_iterations; i++) {
158 tukey_estimator.MEstimator(residues, weights, noise_threshold);
162 std::cout <<
"t_robust=" << t_robust <<
" ms ; t (vpColVector)=" << t <<
" ; ratio=" << (t_robust / t) << std::endl;
164 for (
size_t i = 0; i < weights.
size(); i++) {
165 if (!
vpMath::equal(weights[(
unsigned int)i], weights_col[(
unsigned int)i], noise_threshold)) {
166 std::cerr <<
"Difference between vpRobust::TUKEY and "
167 "vpMbtTukeyEstimator (float)!"
169 std::cerr <<
"weights_col[" << i <<
"]=" << weights_col[(
unsigned int)i] << std::endl;
170 std::cerr <<
"weights[" << i <<
"]=" << weights[(
unsigned int)i] << std::endl;
176 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()