|
@@ -18,21 +18,38 @@ using namespace std;
|
|
|
using namespace NICE;
|
|
|
using namespace OBJREC;
|
|
|
|
|
|
+void GPHIKClassifierNICE::init ( const NICE::Config *conf, const std::string & s_confSection )
|
|
|
+{
|
|
|
+ this->verbose = conf->gB( s_confSection, "verbose", false );
|
|
|
+ this->useSimpleBalancing = conf->gB( s_confSection, "use_simple_balancing", false );
|
|
|
+ this->minSamples = conf->gI( s_confSection, "min_samples", -1 );
|
|
|
+ this->performOptimizationAfterIncrement = conf->gB( s_confSection, "performOptimizationAfterIncrement", true );
|
|
|
+
|
|
|
+ this->classifier = new GPHIKClassifier(conf, s_confSection);
|
|
|
+}
|
|
|
+
|
|
|
+GPHIKClassifierNICE::GPHIKClassifierNICE( )
|
|
|
+{
|
|
|
+ this->classifier = NULL;
|
|
|
+}
|
|
|
|
|
|
GPHIKClassifierNICE::GPHIKClassifierNICE( const Config *conf, const string & confSection )
|
|
|
{
|
|
|
- this->verbose = conf->gB(confSection, "verbose", false);
|
|
|
- this->useSimpleBalancing = conf->gB(confSection, "use_simple_balancing", false);
|
|
|
- this->minSamples = conf->gI(confSection, "min_samples", -1);
|
|
|
- this->performOptimizationAfterIncrement = conf->gB(confSection, "performOptimizationAfterIncrement", true);
|
|
|
+ this->classifier = NULL;
|
|
|
|
|
|
- classifier = new GPHIKClassifier(conf, confSection);
|
|
|
+ // if no config file was given, we either restore the classifier from an external file, or run ::init with
|
|
|
+ // an emtpy config (using default values thereby) when calling the train-method
|
|
|
+ if ( conf != NULL )
|
|
|
+ {
|
|
|
+ this->init(conf, confSection);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
GPHIKClassifierNICE::~GPHIKClassifierNICE()
|
|
|
{
|
|
|
- if ( classifier != NULL )
|
|
|
- delete classifier;
|
|
|
+ if ( this->classifier != NULL )
|
|
|
+ delete this->classifier;
|
|
|
+ this->classifier = NULL;
|
|
|
}
|
|
|
|
|
|
ClassificationResult GPHIKClassifierNICE::classify ( Example & pe )
|
|
@@ -46,6 +63,9 @@ ClassificationResult GPHIKClassifierNICE::classify ( Example & pe )
|
|
|
|
|
|
ClassificationResult GPHIKClassifierNICE::classify ( const NICE::SparseVector * example )
|
|
|
{
|
|
|
+ if ( this->classifier == NULL )
|
|
|
+ fthrow(Exception, "Classifier not trained yet -- aborting!" );
|
|
|
+
|
|
|
NICE::SparseVector scores;
|
|
|
int result;
|
|
|
|
|
@@ -86,6 +106,13 @@ ClassificationResult GPHIKClassifierNICE::classify ( const NICE::SparseVector *
|
|
|
/** training process */
|
|
|
void GPHIKClassifierNICE::train ( FeaturePool & fp, Examples & examples )
|
|
|
{
|
|
|
+ if ( this->classifier == NULL )
|
|
|
+ {
|
|
|
+ std::cerr << "WARNING -- No config used so far, initialize values with empty config file now..." << std::endl;
|
|
|
+ NICE::Config tmpConfEmpty ;
|
|
|
+ this->init ( &tmpConfEmpty );
|
|
|
+ }
|
|
|
+
|
|
|
// we completely ignore the feature pool :)
|
|
|
//
|
|
|
initRand(0);
|