|
@@ -10,6 +10,7 @@
|
|
#endif
|
|
#endif
|
|
|
|
|
|
#include <iostream>
|
|
#include <iostream>
|
|
|
|
+#include <ctime>
|
|
|
|
|
|
#include "vislearning/regression/linregression/LinRegression.h"
|
|
#include "vislearning/regression/linregression/LinRegression.h"
|
|
#include "vislearning/regression/linregression/RANSACReg.h"
|
|
#include "vislearning/regression/linregression/RANSACReg.h"
|
|
@@ -21,6 +22,8 @@ using namespace NICE;
|
|
|
|
|
|
RANSACReg::RANSACReg ( const Config *_conf )
|
|
RANSACReg::RANSACReg ( const Config *_conf )
|
|
{
|
|
{
|
|
|
|
+ if ( _conf->gB("RANSACReg","start_random_generator" ) )
|
|
|
|
+ std::srand ( unsigned ( std::time(0) ) );
|
|
threshold = _conf->gD("RANSACReg","threshold",0.5);
|
|
threshold = _conf->gD("RANSACReg","threshold",0.5);
|
|
iter = _conf->gI("RANSACReg","iterations",10);
|
|
iter = _conf->gI("RANSACReg","iterations",10);
|
|
}
|
|
}
|
|
@@ -39,22 +42,16 @@ RANSACReg::~RANSACReg()
|
|
{
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
-void RANSACReg::teach ( const NICE::VVector & dataSet, const NICE::Vector & labelSet )
|
|
|
|
|
|
+RANSACReg* RANSACReg::clone ( void ) const
|
|
{
|
|
{
|
|
- //for iter iterations do
|
|
|
|
- //choose random subset of n points (n = dataSet[0].size()+1)
|
|
|
|
- //do LinRegression on subset
|
|
|
|
- //get modelParameters
|
|
|
|
- //test how many points, which are not in subset, are close to model (use threshold and distancefunc here) -> these points are consneus set
|
|
|
|
- //if consensus set contains more points than any previous one, take this model as best_model
|
|
|
|
- //maybe compute best_model again with all points of best_consensusSet
|
|
|
|
- //store best_model and maybe best_consensusSet
|
|
|
|
-
|
|
|
|
|
|
+ return new RANSACReg(*this);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void RANSACReg::teach ( const NICE::VVector & dataSet, const NICE::Vector & labelSet )
|
|
|
|
+{
|
|
NICE::VVector best_CS(0,0);
|
|
NICE::VVector best_CS(0,0);
|
|
std::vector<double> best_labelCS;
|
|
std::vector<double> best_labelCS;
|
|
|
|
|
|
- cerr<<"Size of training data: "<<dataSet.size()<<endl;
|
|
|
|
-
|
|
|
|
vector<int> indices;
|
|
vector<int> indices;
|
|
for ( uint i = 0; i < dataSet.size(); i++ )
|
|
for ( uint i = 0; i < dataSet.size(); i++ )
|
|
indices.push_back(i);
|
|
indices.push_back(i);
|
|
@@ -78,6 +75,7 @@ void RANSACReg::teach ( const NICE::VVector & dataSet, const NICE::Vector & labe
|
|
NICE::VVector current_CS;
|
|
NICE::VVector current_CS;
|
|
std::vector<double> current_labelCS;
|
|
std::vector<double> current_labelCS;
|
|
|
|
|
|
|
|
+#pragma omp parallel for
|
|
for ( uint j = n; j < indices.size(); j++ ){ //compute distance between each datapoint and current model
|
|
for ( uint j = n; j < indices.size(); j++ ){ //compute distance between each datapoint and current model
|
|
double lengthNormalVector = 0;
|
|
double lengthNormalVector = 0;
|
|
double sum = 0;
|
|
double sum = 0;
|
|
@@ -87,10 +85,9 @@ void RANSACReg::teach ( const NICE::VVector & dataSet, const NICE::Vector & labe
|
|
}
|
|
}
|
|
lengthNormalVector = sqrt(lengthNormalVector);
|
|
lengthNormalVector = sqrt(lengthNormalVector);
|
|
|
|
|
|
- double distance = ( sum - labelSet[indices[j]] )/ lengthNormalVector;
|
|
|
|
-// cerr<<"distance: "<<distance<<endl;
|
|
|
|
-
|
|
|
|
|
|
+ double distance = ( sum - labelSet[indices[j]] ) / lengthNormalVector;
|
|
|
|
|
|
|
|
+#pragma omp critical
|
|
if ( abs(distance) < threshold ){ //if point is close to model, it belongs to consensus set
|
|
if ( abs(distance) < threshold ){ //if point is close to model, it belongs to consensus set
|
|
current_CS.push_back ( dataSet[indices[j]] );
|
|
current_CS.push_back ( dataSet[indices[j]] );
|
|
current_labelCS.push_back ( labelSet[indices[j]] );
|
|
current_labelCS.push_back ( labelSet[indices[j]] );
|
|
@@ -103,7 +100,6 @@ void RANSACReg::teach ( const NICE::VVector & dataSet, const NICE::Vector & labe
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- cerr<<"Size of best_CS: "<<best_CS.size()<<endl;
|
|
|
|
LinRegression *best_linReg = new LinRegression (); //compute best_model again with all points of best_consensusSet
|
|
LinRegression *best_linReg = new LinRegression (); //compute best_model again with all points of best_consensusSet
|
|
best_linReg->teach ( best_CS, (NICE::Vector)best_labelCS );
|
|
best_linReg->teach ( best_CS, (NICE::Vector)best_labelCS );
|
|
modelParams = best_linReg->getModelParams();
|
|
modelParams = best_linReg->getModelParams();
|