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 = 1
e-3;
58 noise.seed(
static_cast<unsigned int>(time(
nullptr)));
60 vpColVector residues_col(
static_cast<unsigned int>(nb_elements));
62 for (
size_t i = 0;
i < nb_elements;
i++) {
63 residues_col[
static_cast<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[
static_cast<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[
static_cast<unsigned int>(i)], noise_threshold)) {
91 std::cerr <<
"Difference between vpRobust::TUKEY and vpMbtTukeyEstimator (double)!" << std::endl;
92 std::cerr <<
"weights_col[" <<
i <<
"]=" << weights_col[
static_cast<unsigned int>(
i)] << std::endl;
93 std::cerr <<
"weights[" <<
i <<
"]=" << weights[
i] << std::endl;
100 for (
size_t i = 0;
i < nb_elements;
i++) {
101 residues_col[
static_cast<unsigned int>(
i)] = noise();
103 weights_col_save = weights_col;
105 for (
int i = 0;
i < nb_iterations;
i++) {
111 vpMbtTukeyEstimator<float> tukey_estimator;
112 std::vector<float> residues(nb_elements);
113 std::vector<float> weights(nb_elements);
114 for (
size_t i = 0;
i < residues.size();
i++) {
115 residues[
i] =
static_cast<float>(residues_col[
static_cast<unsigned int>(
i)]);
116 weights[
i] =
static_cast<float>(weights_col_save[
static_cast<unsigned int>(
i)]);
120 for (
int i = 0;
i < nb_iterations;
i++) {
121 tukey_estimator.MEstimator(residues, weights,
static_cast<float>(noise_threshold));
125 std::cout <<
"t_robust=" << t_robust <<
" ms ; t (float)=" <<
t <<
" ; ratio=" << (t_robust /
t) << std::endl;
127 for (
size_t i = 0;
i < weights.size();
i++) {
128 if (!
vpMath::equal(weights[i],
static_cast<float>(weights_col[
static_cast<unsigned int>(i)]),
static_cast<float>(noise_threshold))) {
129 std::cerr <<
"Difference between vpRobust::TUKEY and vpMbtTukeyEstimator (float)!" << std::endl;
130 std::cerr <<
"weights_col[" <<
i <<
"]=" << weights_col[
static_cast<unsigned int>(
i)] << std::endl;
131 std::cerr <<
"weights[" <<
i <<
"]=" << weights[
i] << std::endl;
138 for (
size_t i = 0;
i < nb_elements;
i++) {
139 residues_col[
static_cast<unsigned int>(
i)] = noise();
141 weights_col_save = weights_col;
143 for (
int i = 0;
i < nb_iterations;
i++) {
149 vpMbtTukeyEstimator<double> tukey_estimator;
154 for (
int i = 0;
i < nb_iterations;
i++) {
155 tukey_estimator.MEstimator(residues, weights, noise_threshold);
159 std::cout <<
"t_robust=" << t_robust <<
" ms ; t (vpColVector)=" <<
t <<
" ; ratio=" << (t_robust /
t) << std::endl;
161 for (
size_t i = 0;
i < weights.
size();
i++) {
162 if (!
vpMath::equal(weights[
static_cast<unsigned int>(i)], weights_col[
static_cast<unsigned int>(i)], noise_threshold)) {
163 std::cerr <<
"Difference between vpRobust::TUKEY and vpMbtTukeyEstimator (float)!" << std::endl;
164 std::cerr <<
"weights_col[" <<
i <<
"]=" << weights_col[
static_cast<unsigned int>(
i)] << std::endl;
165 std::cerr <<
"weights[" <<
i <<
"]=" << weights[
static_cast<unsigned int>(
i)] << std::endl;
171 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()