45 #include <visp3/core/vpConfig.h> 46 #include <visp3/core/vpGaussRand.h> 47 #include <visp3/core/vpRobust.h> 48 #include <visp3/mbt/vpMbtTukeyEstimator.h> 50 int main(
int ,
const char ** )
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(NULL));
59 vpColVector residues_col((
unsigned int)nb_elements);
60 vpColVector weights_col((
unsigned int)nb_elements, 1.0), weights_col_save;
61 for (
size_t i = 0; i < nb_elements; i++) {
62 residues_col[(
unsigned int)i] = noise();
65 vpRobust robust((
unsigned int)nb_elements);
66 robust.setThreshold(noise_threshold);
68 for (
int i = 0; i < nb_iterations; i++) {
75 vpMbtTukeyEstimator<double> tukey_estimator;
76 std::vector<double> residues(nb_elements);
77 for (
size_t i = 0; i < residues.size(); i++) {
78 residues[i] = residues_col[(
unsigned int)i];
81 std::vector<double> weights(nb_elements, 1);
83 for (
int i = 0; i < nb_iterations; i++) {
84 tukey_estimator.MEstimator(residues, weights, noise_threshold);
88 std::cout <<
"t_robust=" << t_robust <<
" ms ; t (double)=" << t <<
" ; ratio=" << (t_robust / t) << std::endl;
90 for (
size_t i = 0; i < weights.size(); i++) {
91 if (!
vpMath::equal(weights[i], weights_col[(
unsigned int)i], noise_threshold)) {
92 std::cerr <<
"Difference between vpRobust::TUKEY and " 93 "vpMbtTukeyEstimator (double)!" 95 std::cerr <<
"weights_col[" << i <<
"]=" << weights_col[(
unsigned int)i] << std::endl;
96 std::cerr <<
"weights[" << i <<
"]=" << weights[i] << std::endl;
103 for (
size_t i = 0; i < nb_elements; i++) {
104 residues_col[(
unsigned int)i] = noise();
106 weights_col_save = weights_col;
108 for (
int i = 0; i < nb_iterations; i++) {
114 vpMbtTukeyEstimator<float> tukey_estimator;
115 std::vector<float> residues(nb_elements);
116 std::vector<float> weights(nb_elements);
117 for (
size_t i = 0; i < residues.size(); i++) {
118 residues[i] = (float)residues_col[(
unsigned int)i];
119 weights[i] = (float)weights_col_save[(
unsigned int)i];
123 for (
int i = 0; i < nb_iterations; i++) {
124 tukey_estimator.MEstimator(residues, weights, (
float)noise_threshold);
128 std::cout <<
"t_robust=" << t_robust <<
" ms ; t (float)=" << t <<
" ; ratio=" << (t_robust / t) << std::endl;
130 for (
size_t i = 0; i < weights.size(); i++) {
131 if (!
vpMath::equal(weights[i], weights_col[(
unsigned int)i], noise_threshold)) {
132 std::cerr <<
"Difference between vpRobust::TUKEY and " 133 "vpMbtTukeyEstimator (float)!" 135 std::cerr <<
"weights_col[" << i <<
"]=" << weights_col[(
unsigned int)i] << std::endl;
136 std::cerr <<
"weights[" << i <<
"]=" << weights[i] << std::endl;
143 for (
size_t i = 0; i < nb_elements; i++) {
144 residues_col[(
unsigned int)i] = noise();
146 weights_col_save = weights_col;
148 for (
int i = 0; i < nb_iterations; i++) {
154 vpMbtTukeyEstimator<double> tukey_estimator;
159 for (
int i = 0; i < nb_iterations; i++) {
160 tukey_estimator.MEstimator(residues, weights, noise_threshold);
164 std::cout <<
"t_robust=" << t_robust <<
" ms ; t (vpColVector)=" << t <<
" ; ratio=" << (t_robust / t) << std::endl;
166 for (
size_t i = 0; i < weights.
size(); i++) {
167 if (!
vpMath::equal(weights[(
unsigned int)i], weights_col[(
unsigned int)i], noise_threshold)) {
168 std::cerr <<
"Difference between vpRobust::TUKEY and " 169 "vpMbtTukeyEstimator (float)!" 171 std::cerr <<
"weights_col[" << i <<
"]=" << weights_col[(
unsigned int)i] << std::endl;
172 std::cerr <<
"weights[" << i <<
"]=" << weights[(
unsigned int)i] << std::endl;
178 std::cout <<
"vpMbtTukeyEstimator returns the same values than vpRobust::TUKEY." << std::endl;
static bool equal(double x, double y, double s=0.001)
unsigned int size() const
Return the number of elements of the 2D array.
VISP_EXPORT double measureTimeMs()
Class for generating random number with normal probability density.
Implementation of column vector and the associated operations.
Contains an M-Estimator and various influence function.