#include <Base/Common/BIASpragma.hh>
#include "ExampleRANSAC_double.hh"
#include <Base/Math/Random.hh>
#include <vector>
#include <iostream>
#include <iomanip>
#include <float.h>
using namespace BIAS;
using namespace std;
void GenerateRANSAC_doubleData(unsigned int count, double mean, double sigma,
double inlier_fraction, vector<double>& data,
{
if (data.size() != count) data.resize(count);
double outlier_prob;
for (unsigned int i = 0; i < count; i++) {
if (outlier_prob > inlier_fraction) {
} else {
}
}
}
int main(int argc, char *argv[])
{
int res = 0;
vector<vector<double> > data_array;
vector<double> data;
double min = -100.0, max = 100.0;
double minsigma = 0.0, maxsigma = 5.0;
vector<double> mean;
vector<double> sigma;
double inlier_fraction = 0.7;
vector<double> expected_inlier_fraction;
unsigned int sample_size = 2;
bool refine_solution = true;
double inlier_distance_threshold;
double solution;
vector<bool> inliers;
bool debug = false;
double mean_error = 0.0;
double solution_error_threshold;
if (debug) {
}
unsigned int count = argc > 1 ? atoi(argv[1]) : 1000;
unsigned int data_length = argc > 2 ? atoi(argv[2]) : 1000;
cout << endl << "Running " << argv[0] << " " << count << " times with "
<< data_length << " samples per test : " << endl
<< "(call " << argv[0] << " <num_tests> <num_samples> to change "
<< "parameters)" << endl << endl;
data_array.resize(count);
mean.resize(count);
sigma.resize(count);
expected_inlier_fraction.resize(count);
for (unsigned int i = 0; i < count; i++)
{
expected_inlier_fraction[i] = inlier_fraction +
if (expected_inlier_fraction[i] > 1.0)
expected_inlier_fraction[i] = 1.0;
GenerateRANSAC_doubleData(data_length, mean[i], sigma[i], inlier_fraction,
data_array[i], randomizer);
}
for (unsigned int i = 0; i < count; i++)
{
inlier_distance_threshold = 3.0*sigma[i];
solution_error_threshold = 1.5*sigma[i];
if (debug) {
for (unsigned int j = 0; j < data_length; j++)
cout << data_array[i][j] << " ";
cout << endl;
cout <<setw(5)<<i<<":\tmean: "<<mean[i]<<"\tsigma: "<<sigma[i]<<endl;
cout << "inlier_distance_threshold = "<<inlier_distance_threshold<<endl;
cout << "solution_error_threshold = "<<solution_error_threshold<<endl;
cout << "expected_inlier_fraction " << expected_inlier_fraction[i]<<endl;
}
ransac.
Init(data_array[i], sample_size, inlier_distance_threshold,
refine_solution, expected_inlier_fraction[i],
solution_error_threshold);
if (ransac.
SolveMaster(expected_inlier_fraction[i], solution, inliers) < 0)
{
BIASERR("Error running RANSAC_double::SolveMaster()!");
cerr << "- true solution \t" << mean[i] <<" \t"
<< "sigma: "<<sigma[i]<<" \t"
<< "expected_inlier_fraction: "<<expected_inlier_fraction[i]<<endl;
} else {
cerr << "- true solution \t" << mean[i] <<" \t"
<< "sigma: "<<sigma[i]<<" \t"
<< "expected_inlier_fraction: "<<expected_inlier_fraction[i]<<endl
<< " estimated solution \t" << solution <<" \t"
<< "error: "<<fabs(solution-mean[i])<<" \t"
<< "expected_inlier_fraction: "<<expected_inlier_fraction[i]<<endl;
mean_error += (sigma[i]!=0.0) ? (fabs(solution-mean[i])/sigma[i]) :
(fabs(solution-mean[i]) / DBL_MIN);
}
}
mean_error /= (double)count;
cerr << "\n mean error of all tests : " << mean_error << endl << endl;
return res;
}