当前位置: 首页>>代码示例>>C++>>正文


C++ UnSerialization::loadHypotheses方法代码示例

本文整理汇总了C++中UnSerialization::loadHypotheses方法的典型用法代码示例。如果您正苦于以下问题:C++ UnSerialization::loadHypotheses方法的具体用法?C++ UnSerialization::loadHypotheses怎么用?C++ UnSerialization::loadHypotheses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnSerialization的用法示例。


在下文中一共展示了UnSerialization::loadHypotheses方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

	// -----------------------------------------------------------------------
	// -----------------------------------------------------------------------
	DataReader::DataReader(const nor_utils::Args& args, int verbose) : _verbose(verbose), _args(args)
	{				
		string mdpTrainFileName = _args.getValue<string>("traintestmdp", 0);				
		string testFileName = _args.getValue<string>("traintestmdp", 1);				
		string shypFileName = _args.getValue<string>("traintestmdp", 3);
		_numIterations = _args.getValue<int>("traintestmdp", 2);				
		
		string tmpFname = _args.getValue<string>("traintestmdp", 4);
		
		
		
		if (_verbose > 0)
			cout << "Loading arff data for MDP learning..." << flush;
		
		// load the arff
		loadInputData(mdpTrainFileName, testFileName, shypFileName);
		
		if (_verbose > 0)
			cout << "Done." << endl << flush;
		
		
		if (_verbose > 0)
			cout << "Loading strong hypothesis..." << flush;
		
		// The class that loads the weak hypotheses
		UnSerialization us;
		
		// loads them
		us.loadHypotheses(shypFileName, _weakHypotheses, _pTrainData);			
		if (_numIterations<_weakHypotheses.size())
			_weakHypotheses.resize(_numIterations);
		
		if (_verbose > 0)
			cout << "Done." << endl << flush;			
		
		assert( _weakHypotheses.size() >= _numIterations );
		
		// calculate the sum of alphas
		vector<BaseLearner*>::iterator it;
		_sumAlphas=0.0;
		for( it = _weakHypotheses.begin(); it != _weakHypotheses.end(); ++it )
		{
			BaseLearner* currBLearner = *it;
			_sumAlphas += currBLearner->getAlpha();
		}
		
	}
开发者ID:busarobi,项目名称:MDDAG,代码行数:49,代码来源:AdaBoostMDPClassifierAdv.cpp

示例2: init

	// -----------------------------------------------------------------------
	// -----------------------------------------------------------------------
	void AdaBoostMDPClassifier::init()
	{				
		string mdpTrainFileName = _args.getValue<string>("traintestmdp", 0);				
		string testFileName = _args.getValue<string>("traintestmdp", 1);				
		string shypFileName = _args.getValue<string>("traintestmdp", 3);
		_numIterations = _args.getValue<int>("traintestmdp", 2);				
		
		string tmpFname = _args.getValue<string>("traintestmdp", 4);
		
		_outputStream.open( tmpFname.c_str() );
		
		if (_verbose > 0)
			cout << "Loading arff data for MDP learning..." << flush;
		
		// load the arff
		loadInputData(mdpTrainFileName, testFileName, shypFileName);
		
		if (_verbose > 0)
			cout << "Done." << endl << flush;
		
		
		if (_verbose > 0)
			cout << "Loading strong hypothesis..." << flush;
		
		// The class that loads the weak hypotheses
		UnSerialization us;
		
		// loads them
		us.loadHypotheses(shypFileName, _weakHypotheses, _pData);			
		_weakHypotheses.resize(_numIterations);
		
		if (_verbose > 0)
			cout << "Done." << endl << flush;			
		
		assert( _weakHypotheses.size() >= _numIterations );
		
		if (_verbose > 0)
			cout << "Allocating grid world..." << flush;
		
		createGridWorld();
		
		if (_verbose > 0)
			cout << "Done." << endl << flush;			
		
	}
开发者ID:busarobi,项目名称:MDDAG,代码行数:47,代码来源:AdaBoostMDPClassifier.cpp

示例3: resumeWeakLearners

	int FilterBoostLearner::resumeWeakLearners(InputData* pTrainingData)
	{
		if (_resumeShypFileName.empty())
			return 0;

		if (_verbose > 0)
			cout << "Reloading strong hypothesis file <" << _resumeShypFileName << ">.." << flush;

		// The class that loads the weak hypotheses
		UnSerialization us;

		// loads them
		us.loadHypotheses(_resumeShypFileName, _foundHypotheses, pTrainingData, _verbose);

		if (_verbose > 0)
			cout << "Done!" << endl;

		// return the number of iterations found
		return static_cast<int>( _foundHypotheses.size() );
	}
开发者ID:ShenWei,项目名称:src,代码行数:20,代码来源:FilterBoostLearner.cpp

示例4: load

void ParasiteLearner::load(nor_utils::StreamTokenizer& st)
{
   //   cout << "Sorry, you can't load a ParasiteLearner" << endl << flush;
   //   exit(1);
   // Calling the super-class method
   BaseLearner::load(st);

   _signOfAlpha = UnSerialization::seekAndParseEnclosedValue<int>(st, "alphasign");
   _nameBaseLearnerFile = UnSerialization::seekAndParseEnclosedValue<string>(st, "poolfile");
   _selectedIdx = UnSerialization::seekAndParseEnclosedValue<int>(st, "learneridx");

   if (_baseLearners.size() == 0) {
      // load the base learners
      if (_verbose >= 2)
	 cout << "loading " << _nameBaseLearnerFile << ".." << flush;
      UnSerialization us;
      us.loadHypotheses( _nameBaseLearnerFile, _baseLearners, _pTrainingData, _verbose);
      if (_verbose >= 2)
	 cout << "finished " << endl << flush;
   }
}
开发者ID:ShenWei,项目名称:src,代码行数:21,代码来源:ParasiteLearner.cpp

示例5: run

void MDDAGClassifier::run(const string& dataFileName, const string& shypFileName,
                          int numIterations, const string& outResFileName, int numRanksEnclosed)
{
    InputData* pData = loadInputData(dataFileName, shypFileName);

    if (_verbose > 0)
        cout << "Loading strong hypothesis..." << flush;

    // The class that loads the weak hypotheses
    UnSerialization us;

    // Where to put the weak hypotheses
    vector<BaseLearner*> weakHypotheses;

    // loads them
    us.loadHypotheses(shypFileName, weakHypotheses, pData);

    // where the results go
    vector< ExampleResults* > results;

    if (_verbose > 0)
        cout << "Classifying..." << flush;

    // get the results
    computeResults( pData, weakHypotheses, results, numIterations );

    const int numClasses = pData->getNumClasses();

    if (_verbose > 0)
    {
        // well.. if verbose = 0 no results are displayed! :)
        cout << "Done!" << endl;

        vector< vector<float> > rankedError(numRanksEnclosed);

        // Get the per-class error for the numRanksEnclosed-th ranks
        for (int i = 0; i < numRanksEnclosed; ++i)
            getClassError( pData, results, rankedError[i], i );

        // output it
        cout << endl;
        cout << "Error Summary" << endl;
        cout << "=============" << endl;

        for ( int l = 0; l < numClasses; ++l )
        {
            // first rank (winner): rankedError[0]
            cout << "Class '" << pData->getClassMap().getNameFromIdx(l) << "': "
                 << setprecision(4) << rankedError[0][l] * 100 << "%";

            // output the others on its side
            if (numRanksEnclosed > 1 && _verbose > 1)
            {
                cout << " (";
                for (int i = 1; i < numRanksEnclosed; ++i)
                    cout << " " << i+1 << ":[" << setprecision(4) << rankedError[i][l] * 100 << "%]";
                cout << " )";
            }

            cout << endl;
        }

        // the overall error
        cout << "\n--> Overall Error: "
             << setprecision(4) << getOverallError(pData, results, 0) * 100 << "%";

        // output the others on its side
        if (numRanksEnclosed > 1 && _verbose > 1)
        {
            cout << " (";
            for (int i = 1; i < numRanksEnclosed; ++i)
                cout << " " << i+1 << ":[" << setprecision(4) << getOverallError(pData, results, i) * 100 << "%]";
            cout << " )";
        }

        cout << endl;

    } // verbose


    // If asked output the results
    if ( !outResFileName.empty() )
    {
        const int numExamples = pData->getNumExamples();
        ofstream outRes(outResFileName.c_str());

        outRes << "Instance" << '\t' << "Forecast" << '\t' << "Labels" << '\n';

        string exampleName;

        for (int i = 0; i < numExamples; ++i)
        {
            // output the name if it exists, otherwise the number
            // of the example
            exampleName = pData->getExampleName(i);
            if ( exampleName.empty() )
                outRes << i << '\t';
            else
                outRes << exampleName << '\t';

//.........这里部分代码省略.........
开发者ID:busarobi,项目名称:MDDAG2,代码行数:101,代码来源:MDDAGClassifier.cpp

示例6: saveLikelihoods

void MDDAGClassifier::saveLikelihoods(const string& dataFileName, const string& shypFileName,
                                      const string& outFileName, int numIterations)
{
    InputData* pData = loadInputData(dataFileName, shypFileName);

    if (_verbose > 0)
        cout << "Loading strong hypothesis..." << flush;

    // The class that loads the weak hypotheses
    UnSerialization us;

    // Where to put the weak hypotheses
    vector<BaseLearner*> weakHypotheses;

    // loads them
    us.loadHypotheses(shypFileName, weakHypotheses, pData);

    // where the results go
    vector< ExampleResults* > results;

    if (_verbose > 0)
        cout << "Classifying..." << flush;

    const int numClasses = pData->getNumClasses();
    const int numExamples = pData->getNumExamples();


    ofstream outFile(outFileName.c_str());
    string exampleName;

    if (_verbose > 0)
        cout << "Output likelihoods..." << flush;

    // get the results
    /////////////////////////////////////////////////////////////////////
    // computeResults( pData, weakHypotheses, results, numIterations );
    assert( !weakHypotheses.empty() );

    // Initialize the output info
    OutputInfo* pOutInfo = NULL;

    if ( !_outputInfoFile.empty() )
        pOutInfo = new OutputInfo(_outputInfoFile, "err");

    // Creating the results structures. See file Structures.h for the
    // PointResults structure
    results.clear();
    results.reserve(numExamples);
    for (int i = 0; i < numExamples; ++i)
        results.push_back( new ExampleResults(i, numClasses) );

    // sum votes for classes
    vector< AlphaReal > votesForExamples( numClasses );
    vector< AlphaReal > expVotesForExamples( numClasses );

    // iterator over all the weak hypotheses
    vector<BaseLearner*>::const_iterator whyIt;
    int t;

    pOutInfo->initialize( pData );

    // for every feature: 1..T
    for (whyIt = weakHypotheses.begin(), t = 0;
            whyIt != weakHypotheses.end() && t < numIterations; ++whyIt, ++t)
    {
        BaseLearner* currWeakHyp = *whyIt;
        AlphaReal alpha = currWeakHyp->getAlpha();

        // for every point
        for (int i = 0; i < numExamples; ++i)
        {
            // a reference for clarity and speed
            vector<AlphaReal>& currVotesVector = results[i]->getVotesVector();

            // for every class
            for (int l = 0; l < numClasses; ++l)
                currVotesVector[l] += alpha * currWeakHyp->classify(pData, i, l);
        }

        // if needed output the step-by-step information
        if ( pOutInfo )
        {
            pOutInfo->outputIteration(t);
            pOutInfo->outputCustom(pData, currWeakHyp);

            // Margins and edge requires an update of the weight,
            // therefore I keep them out for the moment
            //outInfo.outputMargins(pData, currWeakHyp);
            //outInfo.outputEdge(pData, currWeakHyp);

            pOutInfo->endLine();

        } // for (int i = 0; i < numExamples; ++i)
        // calculate likelihoods from votes

        fill( votesForExamples.begin(), votesForExamples.end(), 0.0 );
        AlphaReal lLambda = 0.0;
        for (int i = 0; i < numExamples; ++i)
        {
            // a reference for clarity and speed
//.........这里部分代码省略.........
开发者ID:busarobi,项目名称:MDDAG2,代码行数:101,代码来源:MDDAGClassifier.cpp

示例7: saveCalibratedPosteriors

void MDDAGClassifier::saveCalibratedPosteriors(const string& dataFileName, const string& shypFileName,
        const string& outFileName, int numIterations)
{
    InputData* pData = loadInputData(dataFileName, shypFileName);

    if (_verbose > 0)
        cout << "Loading strong hypothesis..." << flush;

    // The class that loads the weak hypotheses
    UnSerialization us;

    // Where to put the weak hypotheses
    vector<BaseLearner*> weakHypotheses;

    // loads them
    us.loadHypotheses(shypFileName, weakHypotheses, pData);

    // where the results go
    vector< ExampleResults* > results;

    if (_verbose > 0)
        cout << "Classifying..." << flush;

    // get the results
    computeResults( pData, weakHypotheses, results, numIterations );

    const int numClasses = pData->getNumClasses();
    const int numExamples = pData->getNumExamples();

    ofstream outFile(outFileName.c_str());
    string exampleName;

    if (_verbose > 0)
        cout << "Output posteriors..." << flush;

    for (int i = 0; i < numExamples; ++i)
    {
        // output the name if it exists, otherwise the number
        // of the example
        exampleName = pData->getExampleName(i);
        if ( !exampleName.empty() )
            outFile << exampleName << ',';

        // output the posteriors
        outFile << results[i]->getVotesVector()[0];
        for (int l = 1; l < numClasses; ++l)
            outFile << ',' << results[i]->getVotesVector()[l];
        outFile << '\n';
    }

    if (_verbose > 0)
        cout << "Done!" << endl;

    if (_verbose > 1)
    {
        cout << "\nClass order (You can change it in the header of the data file):" << endl;
        for (int l = 0; l < numClasses; ++l)
            cout << "- " << pData->getClassMap().getNameFromIdx(l) << endl;
    }

    // delete the input data file
    if (pData)
        delete pData;

    vector<ExampleResults*>::iterator it;
    for (it = results.begin(); it != results.end(); ++it)
        delete (*it);
}
开发者ID:busarobi,项目名称:MDDAG2,代码行数:68,代码来源:MDDAGClassifier.cpp

示例8: saveConfusionMatrix

void MDDAGClassifier::saveConfusionMatrix(const string& dataFileName, const string& shypFileName,
        const string& outFileName)
{
    InputData* pData = loadInputData(dataFileName, shypFileName);

    if (_verbose > 0)
        cout << "Loading strong hypothesis..." << flush;

    // The class that loads the weak hypotheses
    UnSerialization us;

    // Where to put the weak hypotheses
    vector<BaseLearner*> weakHypotheses;

    // loads them
    us.loadHypotheses(shypFileName, weakHypotheses, pData);

    // where the results go
    vector< ExampleResults* > results;

    if (_verbose > 0)
        cout << "Classifying..." << flush;

    // get the results
    computeResults( pData, weakHypotheses, results, (int)weakHypotheses.size() );

    const int numClasses = pData->getNumClasses();
    const int numExamples = pData->getNumExamples();

    ofstream outFile(outFileName.c_str());

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

    for (int l = 0; l < numClasses; ++l)
        outFile << '\t' << pData->getClassMap().getNameFromIdx(l);
    outFile << endl;

    for (int l = 0; l < numClasses; ++l)
    {
        vector<int> winnerCount(numClasses, 0);
        for (int i = 0; i < numExamples; ++i)
        {
            if ( pData->hasPositiveLabel(i,l) )
                ++winnerCount[ results[i]->getWinner().first ];
        }

        // class name
        outFile << pData->getClassMap().getNameFromIdx(l);

        for (int j = 0; j < numClasses; ++j)
            outFile << '\t' << winnerCount[j];

        outFile << endl;
    }

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

    if (_verbose > 0)
        cout << "Done!" << endl;

    // delete the input data file
    if (pData)
        delete pData;

    vector<ExampleResults*>::iterator it;
    for (it = results.begin(); it != results.end(); ++it)
        delete (*it);
}
开发者ID:busarobi,项目名称:MDDAG2,代码行数:68,代码来源:MDDAGClassifier.cpp

示例9: printConfusionMatrix

void MDDAGClassifier::printConfusionMatrix(const string& dataFileName, const string& shypFileName)
{
    InputData* pData = loadInputData(dataFileName, shypFileName);

    if (_verbose > 0)
        cout << "Loading strong hypothesis..." << flush;

    // The class that loads the weak hypotheses
    UnSerialization us;

    // Where to put the weak hypotheses
    vector<BaseLearner*> weakHypotheses;

    // loads them
    us.loadHypotheses(shypFileName, weakHypotheses, pData);

    // where the results go
    vector< ExampleResults* > results;

    if (_verbose > 0)
        cout << "Classifying..." << flush;

    // get the results
    computeResults( pData, weakHypotheses, results, (int)weakHypotheses.size());

    const int numClasses = pData->getNumClasses();
    const int numExamples = pData->getNumExamples();

    if (_verbose > 0)
        cout << "Done!" << endl;

    const int colSize = 7;

    if (_verbose > 0)
    {
        cout << "Raw Confusion Matrix:\n";
        cout << setw(colSize) << "Truth       ";

        for (int l = 0; l < numClasses; ++l)
            cout << setw(colSize) << nor_utils::getAlphanumeric(l);

        cout << "\nClassification\n";

        for (int l = 0; l < numClasses; ++l)
        {
            vector<int> winnerCount(numClasses, 0);
            for (int i = 0; i < numExamples; ++i)
            {
                if ( pData->hasPositiveLabel(i, l) )
                    ++winnerCount[ results[i]->getWinner().first ];
            }

            // class
            cout << setw(colSize) << "           " << nor_utils::getAlphanumeric(l);

            for (int j = 0; j < numClasses; ++j)
                cout << setw(colSize) << winnerCount[j];

            cout << endl;
        }

    }

    cout << "\nMatrix Key:\n";

    // Print the legend
    for (int l = 0; l < numClasses; ++l)
        cout << setw(5) << nor_utils::getAlphanumeric(l) << ": " <<
             pData->getClassMap().getNameFromIdx(l) << "\n";

    // delete the input data file
    if (pData)
        delete pData;

    vector<ExampleResults*>::iterator it;
    for (it = results.begin(); it != results.end(); ++it)
        delete (*it);
}
开发者ID:busarobi,项目名称:MDDAG2,代码行数:78,代码来源:MDDAGClassifier.cpp

示例10: saveROC

	void AdaBoostMHClassifier::saveROC(const string& dataFileName, const string& shypFileName, 
		const string& outFileName, int numIterations)
	{
		InputData* pData = loadInputData(dataFileName, shypFileName);
		ofstream outFile(outFileName.c_str());
		
		if ( ! outFile.is_open() )
		{
			cout << "Cannot open outfile" << endl;
			exit( -1 );
		}

		if (_verbose > 0)
			cout << "Loading strong hypothesis..." << flush;

		// The class that loads the weak hypotheses
		UnSerialization us;

		// Where to put the weak hypotheses
		vector<BaseLearner*> weakHypotheses;

		// loads them
		us.loadHypotheses(shypFileName, weakHypotheses, pData);
		weakHypotheses.resize( numIterations );

		// where the results go
		vector< ExampleResults* > results;

		if (_verbose > 0)
			cout << "Classifying..." << flush;

		// get the results
		computeResults( pData, weakHypotheses, results, weakHypotheses.size());

		const int numClasses = pData->getNumClasses();
		const int numExamples = pData->getNumExamples();

		if (_verbose > 0)
			cout << "Done!" << endl;		

		vector< pair< int, double> > sortedExample( numExamples );
		
		for( int i=0; i<numExamples; i++ )
		{
			sortedExample[i].first = i;
			sortedExample[i].second = results[i]->getVotesVector()[0];
		}
		sort( sortedExample.begin(), sortedExample.end(), nor_utils::comparePair< 2, int, double, greater<double> >() );

		vector<double> positiveWeights( numExamples );
		double sumOfPositiveWeights = 0.0;

		vector<double>  negativeWeights( numExamples );
		double sumOfNegativeWeights = 0.0;
		
		fill( positiveWeights.begin(), positiveWeights.end(), 0.0 );
		fill( negativeWeights.begin(), negativeWeights.end(), 0.0 );

		string className = pData->getClassMap().getNameFromIdx( 0 );

		vector<Label>& labels = pData->getLabels( sortedExample[0].first );
		vector<Label>::iterator labIt = find( labels.begin(), labels.end(), 0);
		
		if ( labIt != labels.end() )
		{
			if ( labIt->y > 0.0 )
			{
				positiveWeights[0] = labIt->initialWeight;
				sumOfPositiveWeights += labIt->initialWeight;
			} else
			{
				negativeWeights[0] = labIt->initialWeight;
				sumOfNegativeWeights += labIt->initialWeight;
			}
		}
		
		for( int i=1; i<numExamples; i++ )
		{
			labels = pData->getLabels( sortedExample[i].first );
			labIt = find( labels.begin(), labels.end(), 0);
			if ( labIt != labels.end() )
			{
				if ( labIt->y > 0.0 )
				{
					negativeWeights[i] = negativeWeights[i-1];
					positiveWeights[i] = positiveWeights[i-1] + labIt->initialWeight;
					sumOfPositiveWeights += labIt->initialWeight;
				} else
				{
					positiveWeights[i] = positiveWeights[i-1];
					negativeWeights[i] = negativeWeights[i-1] + labIt->initialWeight;
					sumOfNegativeWeights += labIt->initialWeight;
				}
			} else {
				positiveWeights[i] = positiveWeights[i-1];
				negativeWeights[i] = negativeWeights[i-1];
			}
		}

		outFile << "Class name: " << className << endl;
//.........这里部分代码省略.........
开发者ID:ShenWei,项目名称:src,代码行数:101,代码来源:AdaBoostMHClassifier.cpp

示例11: run

float ParasiteLearner::run()
{
   if (_baseLearners.size() == 0) {
      // load the base learners
      if (_verbose >= 2)
	 cout << "loading " << _nameBaseLearnerFile << ".." << flush;
      UnSerialization us;
      us.loadHypotheses( _nameBaseLearnerFile, _baseLearners, _pTrainingData, _verbose);
      if (_verbose >= 2)
	 cout << "finished " << endl << flush;
   }
   
   if ( _numBaseLearners == -1 || _numBaseLearners > _baseLearners.size())
      _numBaseLearners = _baseLearners.size();
   
   
   const int numClasses = _pTrainingData->getNumClasses();
   const int numExamples = _pTrainingData->getNumExamples();
   float tmpAlpha;
   float bestE = numeric_limits<float>::max();
   float sumGamma, bestSumGamma = -numeric_limits<float>::max();
   float tmpE, gamma;
   float eps_min,eps_pls;
   int tmpSignOfAlpha;

   // This is the bottleneck, squeeze out every microsecond
   if (_closed) {
      bestSumGamma = 0;
      if ( nor_utils::is_zero(_theta) ) {
	 for (int j = 0; j < _numBaseLearners; ++j) {
	    sumGamma = 0;
	    for (int i = 0; i < numExamples; ++i) {
	       vector<Label> labels = _pTrainingData->getLabels(i);
	       for (int l = 0; l < numClasses; ++l)
		  sumGamma += labels[l].weight * 
		     _baseLearners[j]->classify(_pTrainingData,i,l) * labels[l].y;
	    }
	    if (fabs(sumGamma) > fabs(bestSumGamma)) {
	       _selectedIdx = j;
	       bestSumGamma = sumGamma;
	    }
	 }
	 eps_pls = eps_min = 0;
	 for (int i = 0; i < numExamples; ++i) {
	    vector<Label> labels = _pTrainingData->getLabels(i);
	    for (int l = 0; l < numClasses; ++l) {
	       gamma = _baseLearners[_selectedIdx]->classify(_pTrainingData,i,l) *
		  labels[l].y;
	       if ( gamma > 0 )
		  eps_pls += labels[l].weight;
	       else if ( gamma < 0 )
		  eps_min += labels[l].weight;
	    }
	 }
	 if (eps_min > eps_pls) {
	    float tmpSwap = eps_min;
	    eps_min = eps_pls;
	    eps_pls = tmpSwap;
	    _signOfAlpha = -1;
	 }
	 _alpha = getAlpha(eps_min, eps_pls);
	 bestE = BaseLearner::getEnergy( eps_min, eps_pls );
      }
      else {
	 for (int j = 0; j < _numBaseLearners; ++j) {
	    eps_pls = eps_min = 0;
	    for (int i = 0; i < numExamples; ++i) {
	       vector<Label> labels = _pTrainingData->getLabels(i);
	       for (int l = 0; l < numClasses; ++l) {
		  gamma = _baseLearners[j]->classify(_pTrainingData,i,l) * labels[l].y;
		  if ( gamma > 0 )
		     eps_pls += labels[l].weight;
		  else if ( gamma < 0 )
		     eps_min += labels[l].weight;
	       }
	    }
	    if (eps_min > eps_pls) {
	       float tmpSwap = eps_min;
	       eps_min = eps_pls;
	       eps_pls = tmpSwap;
	       tmpSignOfAlpha = -1;
	    }
	    else
	       tmpSignOfAlpha = 1;
	    tmpAlpha = getAlpha(eps_min, eps_pls, _theta);
	    tmpE = BaseLearner::getEnergy( eps_min, eps_pls, tmpAlpha, _theta );
	    if (tmpE < bestE && eps_pls > eps_min + _theta) {
	       _alpha = tmpAlpha;
	       _selectedIdx = j;
	       _signOfAlpha = tmpSignOfAlpha;
	       bestE = tmpE;
	    }
	 }
      }
   }
   else {
      if ( nor_utils::is_zero(_theta) ) {
	 for (int j = 0; j < _numBaseLearners; ++j) {
	    sumGamma = 0;
	    for (int i = 0; i < numExamples; ++i) {
//.........这里部分代码省略.........
开发者ID:ShenWei,项目名称:src,代码行数:101,代码来源:ParasiteLearner.cpp

示例12: run


//.........这里部分代码省略.........

        // FIXME: output posteriors

//        OutputInfo* pTrainPosteriorsOut = NULL;
//        OutputInfo* pTestPosteriorsOut = NULL;
        
//        if (! _trainPosteriorsFileName.empty()) {
//            pTrainPosteriorsOut = new OutputInfo(_trainPosteriorsFileName, "pos", true);
//            pTrainPosteriorsOut->initialize(pTrainingData);
//            dynamic_cast<PosteriorsOutput*>( pTrainPosteriorsOut->getOutputInfoObject("pos") )->addClassIndex(_positiveLabelIndex );
//        }
        
//        if (! _testPosteriorsFileName.empty() && !_testFileName.empty() ) {
//            pTestPosteriorsOut = new OutputInfo(_testPosteriorsFileName, "pos", true);
//            pTestPosteriorsOut->initialize(pTestData);
//            dynamic_cast<PosteriorsOutput*>( pTestPosteriorsOut->getOutputInfoObject("pos") )->addClassIndex(_positiveLabelIndex );            
//        }
        
        const int numExamples = pTrainingData->getNumExamples();

        vector<BaseLearner*> inWeakHypotheses;
        
        if (_fullRun) {            
            // TODO : the full training is implementet, testing is needed
            AdaBoostMHLearner* sHypothesis = new AdaBoostMHLearner();
            sHypothesis->run(args, pTrainingData, _baseLearnerName, _numIterations, inWeakHypotheses );
            delete sHypothesis;
        }
        else { 
            
            cout << "[+] Loading uncalibrated shyp file... ";
            //read the shyp file of the trained classifier
            UnSerialization us;
            us.loadHypotheses(_unCalibratedShypFileName, inWeakHypotheses, pTrainingData);  
            if (_inShypLimit > 0 && _inShypLimit < inWeakHypotheses.size() ) {
                inWeakHypotheses.resize(_inShypLimit);
            }
            if (_numIterations > inWeakHypotheses.size()) {
                _numIterations = inWeakHypotheses.size();
            }
            cout << "weak hypotheses loaded, " << inWeakHypotheses.size() << " retained.\n";
        }
        
        // some initializations
        _foundHypotheses.resize(0);
        double faceRejectionFraction = 0.;
        double estimatedExecutionTime = 0.;
        vector<double> rejectionDistributionVector;

        _rejectionThresholds.resize(0);
        
        
        set<int> trainingIndices;
        for (int i = 0; i < numExamples; i++) {
            trainingIndices.insert(pTrainingData->getRawIndex(i) );
        }
        
        // init v_t (see the paper)
        initializeRejectionDistributionVector(_numIterations, rejectionDistributionVector);

        if (_verbose == 1)
            cout << "Learning in progress..." << endl;

        ///////////////////////////////////////////////////////////////////////
        // Starting the SoftCascade main loop
        ///////////////////////////////////////////////////////////////////////
开发者ID:junjiek,项目名称:cmu-exp,代码行数:67,代码来源:SoftCascadeLearner.cpp


注:本文中的UnSerialization::loadHypotheses方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。