Exemplo n.º 1
0
	void TreeLearner::initLearningOptions(const nor_utils::Args& args)
	{
		BaseLearner::initLearningOptions(args);
		
		string baseLearnerName;
		args.getValue("baselearnertype", 0, baseLearnerName);   
		args.getValue("baselearnertype", 1, _numBaseLearners);   
		
		// get the registered weak learner (type from name)
		BaseLearner* pWeakHypothesisSource = BaseLearner::RegisteredLearners().getLearner(baseLearnerName);
		
		//check whether the weak learner is a ScalarLeaerner
		try {
			_pScalaWeakHypothesisSource = dynamic_cast<ScalarLearner*>(pWeakHypothesisSource);
		}
		catch (bad_cast& e) {
			cerr << "The weak hypothesis must be a ScalarLearner!!!" << endl;
			exit(-1);
		}
		
		_pScalaWeakHypothesisSource->initLearningOptions(args);
		
		/*
		 for( int ib = 0; ib < _numBaseLearners; ++ib ) {			
		 vector< int > tmpVector( 2, -1 );
		 _idxPairs.push_back( tmpVector );
		 }
		 */
	}
Exemplo n.º 2
0
	void BaseLearner::initLearningOptions(const nor_utils::Args& args)
	{
		if ( args.hasArgument("verbose") )
			args.getValue("verbose", 0, _verbose);

		// Set the value of theta
		if ( args.hasArgument("edgeoffset") )
			args.getValue("edgeoffset", 0, _theta);   
	}
Exemplo n.º 3
0
void ParasiteLearner::initLearningOptions(const nor_utils::Args& args)
{
   BaseLearner::initLearningOptions(args);

   args.getValue("pool", 0, _nameBaseLearnerFile);   
   args.getValue("pool", 1, _numBaseLearners);   

   if ( args.hasArgument("closed") )
      _closed = 1;
}
Exemplo n.º 4
0
	VJCascadeClassifier::VJCascadeClassifier(const nor_utils::Args &args, int verbose)
	: _verbose(verbose), _args(args), _positiveLabelIndex(-1)
	{
		// The file with the step-by-step information
		if ( args.hasArgument("outputinfo") )
			args.getValue("outputinfo", 0, _outputInfoFile);
		
		if ( args.hasArgument("positivelabel") )
		{
			args.getValue("positivelabel", 0, _positiveLabelName);
		} else {
			cout << "The name of positive label has to be given!!!" << endl;
			exit(-1);
		}				
	}
Exemplo n.º 5
0
MDDAGClassifier::MDDAGClassifier(const nor_utils::Args &args, int verbose)
    : _verbose(verbose), _args(args)
{
    // The file with the step-by-step information
    if ( args.hasArgument("outputinfo") )
        args.getValue("outputinfo", 0, _outputInfoFile);
}
Exemplo n.º 6
0
	void StochasticLearner::initLearningOptions(const nor_utils::Args& args)
	{
		BaseLearner::initLearningOptions(args);
		
		if (args.hasArgument("initgamma"))
			args.getValue("initgamma", 0, _initialGammat);   		
		
		if (args.hasArgument("gammdivperiod"))
			args.getValue("gammdivperiod", 0, _gammdivperiod);   		
		
		
		if (args.hasArgument("graditer"))
			args.getValue("graditer", 0, _maxIter);   		
		
		if (args.hasArgument("gradmethod"))
		{
			string gradMethod;
			args.getValue("gradmethod", 0, gradMethod);   		
			
			if ( gradMethod.compare( "sgd" ) == 0 )
				_gMethod = OPT_SGD;
			else if ( gradMethod.compare( "bgd" ) == 0 )
				_gMethod = OPT_BGD;
			else {
				cerr << "SigmoidSingleStumpLearner::Unknown update gradient method" << endl;
				exit( -1 );
			}					
		}		
		
		if (args.hasArgument("tfunc"))
		{
			string targetFunction;
			args.getValue("tfunc", 0, targetFunction);
			
			if ( targetFunction.compare( "exploss" ) == 0 )
				_tFunction = TF_EXPLOSS;
			else if ( targetFunction.compare( "edge" ) == 0 )
				_tFunction = TF_EDGE;
			else {
				cerr << "SigmoidSingleStumpLearner::Unknown target function" << endl;
				exit( -1 );				
			}					
			
		}
		
	}
Exemplo n.º 7
0
	void EnumLearnerSA::initLearningOptions(const nor_utils::Args& args)
	{
		BaseLearner::initLearningOptions(args);

		if ( args.hasArgument( "uoffset" ) )  
			args.getValue("uoffset", 0, _uOffset);   

	}
Exemplo n.º 8
0
void MultiMDDAGLearner::getArgs(const nor_utils::Args& args)
{
    MDDAGLearner::getArgs(args);

    // Set the value of theta
    if ( args.hasArgument("updateperc") )
        args.getValue("updateperc", 0, _randomNPercent);

}
Exemplo n.º 9
0
	void ProductLearner::initLearningOptions(const nor_utils::Args& args)
	{
		BaseLearner::initLearningOptions(args);

		string baseLearnerName;
		args.getValue("baselearnertype", 0, baseLearnerName);   
		args.getValue("baselearnertype", 1, _numBaseLearners);   

		// get the registered weak learner (type from name)
		BaseLearner* pWeakHypothesisSource = 
			BaseLearner::RegisteredLearners().getLearner(baseLearnerName);
		pWeakHypothesisSource->initLearningOptions(args);

		for( int ib = 0; ib < _numBaseLearners; ++ib ) {
			_baseLearners.push_back(pWeakHypothesisSource->create());
			_baseLearners[ib]->initLearningOptions(args);
		}
	}
Exemplo n.º 10
0
	void FilterBoostLearner::getArgs(const nor_utils::Args& args)
	{
		AdaBoostMHLearner::getArgs( args );
		// Set the value of the sample size
		if ( args.hasArgument("Cn") )
		{
			args.getValue("C", 0, _Cn);
			if (_verbose > 1)
				cout << "--> Resampling size: " << _Cn << endl;
		}

	}
Exemplo n.º 11
0
int MultiMDDAGLearner::resumeProcess(const nor_utils::Args& args, InputData* pTestData)
{
    int numPolicies = 0;

    AlphaReal policyAlpha = 0.0;

    if ( args.hasArgument("policyalpha") )
        args.getValue("policyalpha", 0, policyAlpha);

    _policy = new AdaBoostArrayOfPolicyArray(args, _actionNumber);

    return numPolicies;
}
Exemplo n.º 12
0
 void SoftCascadeLearner::classify(const nor_utils::Args& args)
 {
     SoftCascadeClassifier classifier(args, _verbose);
             
     string testFileName = args.getValue<string>("test", 0);
     string shypFileName = args.getValue<string>("test", 1);
     int numIterations = args.getValue<int>("test", 2);
             
     string outResFileName = "";
     if ( args.getNumValues("test") > 3 )
         args.getValue("test", 3, outResFileName);
             
     classifier.run(testFileName, shypFileName, numIterations, outResFileName);
 }
Exemplo n.º 13
0
	void FilterBoostLearner::classify(const nor_utils::Args& args)
	{
		FilterBoostClassifier classifier(args, _verbose);

		// -test <dataFile> <shypFile>
		string testFileName = args.getValue<string>("test", 0);
		string shypFileName = args.getValue<string>("test", 1);
		int numIterations = args.getValue<int>("test", 2);

		string outResFileName;
		if ( args.getNumValues("test") > 3 )
			args.getValue("test", 3, outResFileName);

		classifier.run(testFileName, shypFileName, numIterations, outResFileName);
	}
Exemplo n.º 14
0
void TreeLearnerUCT::initLearningOptions(const nor_utils::Args& args)
{
    BaseLearner::initLearningOptions(args);

    string baseLearnerName;
    args.getValue("baselearnertype", 0, baseLearnerName);
    args.getValue("baselearnertype", 1, _numBaseLearners);

    // get the registered weak learner (type from name)
    BaseLearner* pWeakHypothesisSource =
        BaseLearner::RegisteredLearners().getLearner(baseLearnerName);

    for( int ib = 0; ib < _numBaseLearners; ++ib ) {
        _baseLearners.push_back(pWeakHypothesisSource->create());
        _baseLearners[ib]->initLearningOptions(args);

        vector< int > tmpVector( 2, -1 );
        _idxPairs.push_back( tmpVector );
    }

    string updateRule = "";
    if ( args.hasArgument( "updaterule" ) )
        args.getValue("updaterule", 0, updateRule );

    if ( updateRule.compare( "edge" ) == 0 )
        _updateRule = EDGE_SQUARE;
    else if ( updateRule.compare( "alphas" ) == 0 )
        _updateRule = ALPHAS;
    else if ( updateRule.compare( "edgesquare" ) == 0 )
        _updateRule = ESQUARE;
    else {
        cerr << "Unknown update rule in ProductLearnerUCT (set to default [edge]" << endl;
        _updateRule = EDGE_SQUARE;
    }

}
Exemplo n.º 15
0
// -----------------------------------------------------------------------
	void BanditLearner::initLearningOptions(const nor_utils::Args& args)
	{
		BaseLearner::initLearningOptions(args);

		string updateRule = "";
		if ( args.hasArgument( "updaterule" ) )
			args.getValue("updaterule", 0, updateRule );   

		if ( updateRule.compare( "edge" ) == 0 )
			_updateRule = EDGE_SQUARE;
		else if ( updateRule.compare( "logedge" ) == 0 )
			_updateRule = LOGEDGE;
		else if ( updateRule.compare( "alphas" ) == 0 )
			_updateRule = ALPHAS;
		else if ( updateRule.compare( "edgesquare" ) == 0 )
			_updateRule = ESQUARE;
		else {
			//cerr << "Unknown update rule in ProductLearnerUCT (set to default [edge]" << endl;
			_updateRule = LOGEDGE;
		}

		if ( args.hasArgument( "rsample" ) ){
			_K = args.getValue<int>("rsample", 0);
		}

		string banditAlgoName = "";
		if ( args.hasArgument( "banditalgo" ) )
			args.getValue("banditalgo", 0, banditAlgoName ); 

		if ( banditAlgoName.compare( "Random" ) == 0 )
			_banditAlgoName = BA_RANDOM_LS;
		else if ( banditAlgoName.compare( "UCBK" ) == 0 )
			_banditAlgoName = BA_UCBK_LS;
		else if ( banditAlgoName.compare( "UCBKR" ) == 0 )
			_banditAlgoName = BA_UCBKR_LS;
		else if ( banditAlgoName.compare( "UCBKV" ) == 0 )
			_banditAlgoName = BA_UCBKV_LS;
		else if ( banditAlgoName.compare( "EXP3" ) == 0 )
			_banditAlgoName = BA_EXP3_LS;
		else if ( banditAlgoName.compare( "EXP3G" ) == 0 )
			_banditAlgoName = BA_EXP3G_LS;
		else if ( banditAlgoName.compare( "UCT" ) == 0 )
			_banditAlgoName = BA_UCT_LS;
		else {
			cerr << "Unknown bandit algo (BanditSingleStumpLearner)" << endl;
			_banditAlgoName = BA_EXP3_LS;
		}

		if ( _banditAlgo == NULL ) {
			switch ( _banditAlgoName )
			{
				case BA_RANDOM_LS:
					//_banditAlgo =  new Random();
					break;	
				case BA_UCBK_LS:
					//_banditAlgo =  new UCBK();
					break;
				case BA_UCBKV_LS:
					//_banditAlgo =  new UCBKV();
					break;
				case BA_UCBKR_LS:
					//_banditAlgo = new UCBKRandomized();
					break;
				case BA_EXP3_LS:
					_banditAlgo = dynamic_cast<GenericBanditAlgorithmLS<double,string>*>( new Exp3LS<double,string>());
					break;
				case BA_EXP3G_LS:
					_banditAlgo = dynamic_cast<GenericBanditAlgorithmLS<double,string>*>(new Exp3GLS<double,string>());
					break;
				case BA_UCT_LS:					
					_banditAlgo = dynamic_cast<GenericBanditAlgorithmLS<double,string>*>(new UCT<double,string>());
					break;
				default:
					cerr << "There is no bandit algorithm to be given!" << endl;
					exit( -1 );
			}			
		}

	}
Exemplo n.º 16
0
	void BanditSingleStumpLearner::initLearningOptions(const nor_utils::Args& args)
	{
		FeaturewiseLearner::initLearningOptions(args);

		string updateRule = "";
		if ( args.hasArgument( "updaterule" ) )
			args.getValue("updaterule", 0, updateRule );   

		if ( updateRule.compare( "edge" ) == 0 )
			_updateRule = EDGE_SQUARE;
		else if ( updateRule.compare( "logedge" ) == 0 )
			_updateRule = LOGEDGE;
		else if ( updateRule.compare( "alphas" ) == 0 )
			_updateRule = ALPHAS;
		else if ( updateRule.compare( "edgesquare" ) == 0 )
			_updateRule = ESQUARE;
		else {
			//cerr << "Unknown update rule in ProductLearnerUCT (set to default [logedge]" << endl;
			_updateRule = LOGEDGE;
		}

		if ( args.hasArgument( "percent" ) ){
			_percentage = args.getValue<double>("percent", 0);
		} else {
			_percentage = 0.1;
		}

		if ( args.hasArgument( "rsample" ) ){
			_K = args.getValue<int>("rsample", 0);
		} else {
			_K = 1;
		}


		string banditAlgoName = "";
		if ( args.hasArgument( "banditalgo" ) )
			args.getValue("banditalgo", 0, banditAlgoName ); 

		if ( banditAlgoName.compare( "Random" ) == 0 )
			_banditAlgoName = BA_RANDOM;
		else if ( banditAlgoName.compare( "UCBK" ) == 0 )
			_banditAlgoName = BA_UCBK;
		else if ( banditAlgoName.compare( "UCBKR" ) == 0 )
			_banditAlgoName = BA_UCBKR;
		else if ( banditAlgoName.compare( "UCBKV" ) == 0 )
			_banditAlgoName = BA_UCBKV;
		else if ( banditAlgoName.compare( "EXP3" ) == 0 )
			_banditAlgoName = BA_EXP3;
		else if ( banditAlgoName.compare( "EXP3G" ) == 0 )
			_banditAlgoName = BA_EXP3G;
		else if ( banditAlgoName.compare( "EXP3G2" ) == 0 )
			_banditAlgoName = BA_EXP3G2;
		else if ( banditAlgoName.compare( "EXP3P" ) == 0 )
			_banditAlgoName = BA_EXP3P;
		else {
			cerr << "Unknown bandit algo (BanditSingleStumpLearner)" << endl;
			_banditAlgoName = BA_UCBK;
		}

		if ( _banditAlgo == NULL ) {
			switch ( _banditAlgoName )
			{
				case BA_RANDOM:
					_banditAlgo =  new Random();
					break;	
				case BA_UCBK:
					_banditAlgo =  new UCBK();
					break;
				case BA_UCBKV:
					_banditAlgo =  new UCBKV();
					break;
				case BA_UCBKR:
					_banditAlgo = new UCBKRandomized();
					break;
				case BA_EXP3:
					_banditAlgo = new Exp3();
					break;
				case BA_EXP3G:
					_banditAlgo = new Exp3G();
					break;
				case BA_EXP3G2:
					_banditAlgo = new Exp3G2();
					break;
				case BA_EXP3P:
					_banditAlgo = new Exp3P();
					break;
				default:
					cerr << "There is no bandit algorithm to be given!" << endl;
					exit( -1 );
			}
			// the bandit algorithm object must be initilaized once only
			_banditAlgo->initLearningOptions( args );
		}

		
	}
Exemplo n.º 17
0
	void FilterBoostLearner::getArgs(const nor_utils::Args& args)
	{
		if ( args.hasArgument("verbose") )
			args.getValue("verbose", 0, _verbose);

		// The file with the step-by-step information
		if ( args.hasArgument("outputinfo") )
			args.getValue("outputinfo", 0, _outputInfoFile);

		///////////////////////////////////////////////////
		// get the output strong hypothesis file name, if given
		if ( args.hasArgument("shypname") )
			args.getValue("shypname", 0, _shypFileName);
		else
			_shypFileName = string(SHYP_NAME);

		_shypFileName = nor_utils::addAndCheckExtension(_shypFileName, SHYP_EXTENSION);

		///////////////////////////////////////////////////
		// get the output strong hypothesis file name, if given
		if ( args.hasArgument("shypcomp") )
			args.getValue("shypcomp", 0, _isShypCompressed );
		else
			_isShypCompressed = false;


		///////////////////////////////////////////////////
		// Set time limit
		if ( args.hasArgument("timelimit") )
		{
			args.getValue("timelimit", 0, _maxTime);   
			if (_verbose > 1)    
				cout << "--> Overall Time Limit: " << _maxTime << " minutes" << endl;
		}

		// Set the value of theta
		if ( args.hasArgument("edgeoffset") )
			args.getValue("edgeoffset", 0, _theta);  

		// Set the filename of the strong hypothesis file in the case resume is
		// called
		if ( args.hasArgument("resume") )
			args.getValue("resume", 0, _resumeShypFileName);

		// get the name of the learner
		_baseLearnerName = defaultLearner;
		if ( args.hasArgument("learnertype") )
			args.getValue("learnertype", 0, _baseLearnerName);

		// -train <dataFile> <nInterations>
		if ( args.hasArgument("train") )
		{
			args.getValue("train", 0, _trainFileName);
			args.getValue("train", 1, _numIterations);
		}
		// -traintest <trainingDataFile> <testDataFile> <nInterations>
		else if ( args.hasArgument("traintest") ) 
		{
			args.getValue("traintest", 0, _trainFileName);
			args.getValue("traintest", 1, _testFileName);
			args.getValue("traintest", 2, _numIterations);
		}

		// --constant: check constant learner in each iteration
		if ( args.hasArgument("constant") )
			_withConstantLearner = true;

		// Set the value of the sample size
		if ( args.hasArgument("Cn") )
		{
			args.getValue("Cn", 0, _Cn);
			if (_verbose > 1)
				cout << "--> Resampling size: " << _Cn << endl;
		}

	}
Exemplo n.º 18
0
    void SoftCascadeLearner::getArgs(const nor_utils::Args& args)
    {
        if ( args.hasArgument("verbose") )
            args.getValue("verbose", 0, _verbose);

        ///////////////////////////////////////////////////
        // get the output strong hypothesis file name, if given
        if ( args.hasArgument("shypname") )
            args.getValue("shypname", 0, _shypFileName);
        else
            _shypFileName = string(SHYP_NAME);

        _shypFileName = nor_utils::addAndCheckExtension(_shypFileName, SHYP_EXTENSION);


        ///////////////////////////////////////////////////

        //TODO : create an abstract classe for cascade compliant base learners and accept only its offspring!
        // get the name of the learner
        _baseLearnerName = defaultLearner;
        if ( args.hasArgument("learnertype") )
            args.getValue("learnertype", 0, _baseLearnerName);
//            cout << "! Only HaarSingleStumpeLearner is allowed.\n";
        
        // -train <dataFile> <nInterations>
        if ( args.hasArgument("train") )
        {
            args.getValue("train", 0, _trainFileName);
            args.getValue("train", 1, _numIterations);
        }
        // -traintest <trainingDataFile> <testDataFile> <nInterations>
        else if ( args.hasArgument("traintest") ) 
        {
            args.getValue("traintest", 0, _trainFileName);
            args.getValue("traintest", 1, _testFileName);
            args.getValue("traintest", 2, _numIterations);
        }

        // The file with the step-by-step information
        if ( args.hasArgument("outputinfo") )
            args.getValue("outputinfo", 0, _outputInfoFile);
        else
            _outputInfoFile = OUTPUT_NAME;
        
        // --constant: check constant learner in each iteration
        if ( args.hasArgument("constant") )
            _withConstantLearner = true;
        
        if ( args.hasArgument("positivelabel") )
        {
            args.getValue("positivelabel", 0, _positiveLabelName);
        } else {
            cout << "Error : The name of positive label must to given. \n Type --h softcascade to know the mandatory options." << endl;
            exit(-1);
        }
        
        if (args.hasArgument("trainposteriors")) {
            args.getValue("trainposteriors", 0, _trainPosteriorsFileName);
        }

        if (args.hasArgument("testposteriors")) {
            args.getValue("testposteriors", 0, _testPosteriorsFileName);
        }

        if (args.hasArgument("detectionrate")) {
            args.getValue("detectionrate", 0, _targetDetectionRate);
        }
        else {
            cout << "Error : the target detection rate must be given. \n Type --h softcascade to know the mandatory options.";
            exit(-1);
        }

        
        if (args.hasArgument("expalpha")) {
            args.getValue("expalpha", 0, _alphaExponentialParameter);
        }
        else {
            cout << "Error : the parameter used to initialize the rejection distribution vector must be given. \n Type --h softcascade to know the mandatory options.";
            exit(-1);
        }

        if (args.hasArgument("calibrate")) {
            args.getValue("calibrate", 0, _unCalibratedShypFileName);
            if (args.getNumValues("calibrate") > 1) {
                args.getValue("calibrate", 0, _inShypLimit);
            }
        }
        else {
            _fullRun = true;
            _unCalibratedShypFileName = "shypToBeCalibrated.xml";
            cout << "The strong hypothesis file will be seved into the file " << _unCalibratedShypFileName;
            //cout << "Error : the shyp file of the uncalibrated trained classifier must be given ! \n";
            //exit(-1);

        }
        
        if (args.hasArgument("bootstrap")) {
            cout << "Warning ! The bootstrapping set and the training set must come from the same superset. \n";
            args.getValue("bootstrap", 0, _bootstrapFileName);
            args.getValue("bootstrap", 1, _bootstrapRate);
        }
    }