本文整理汇总了C++中BaseLearner::setAlpha方法的典型用法代码示例。如果您正苦于以下问题:C++ BaseLearner::setAlpha方法的具体用法?C++ BaseLearner::setAlpha怎么用?C++ BaseLearner::setAlpha使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseLearner
的用法示例。
在下文中一共展示了BaseLearner::setAlpha方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
//.........这里部分代码省略.........
filter( pTrainingData, currentNumberOfUsedData );
if ( pTrainingData->getNumExamples() < 2 )
{
filter( pTrainingData, currentNumberOfUsedData, false );
}
if (_verbose > 1)
{
cout << "--> Size of training data = " << pTrainingData->getNumExamples() << endl;
}
energy = pWeakHypothesis->run();
pConstantWeakHypothesis->run();
}
//estimate edge
filter( pTrainingData, currentNumberOfUsedData, false );
edge = pWeakHypothesis->getEdge(true) / 2.0;
constantEdge = pConstantWeakHypothesis->getEdge() / 2.0;
if ( constantEdge > edge )
{
delete pWeakHypothesis;
pWeakHypothesis = pConstantWeakHypothesis;
edge = constantEdge;
} else {
delete pConstantWeakHypothesis;
}
// calculate alpha
AlphaReal alpha = 0.0;
alpha = 0.5 * log( ( 1 + edge ) / ( 1 - edge ) );
pWeakHypothesis->setAlpha( alpha );
_sumAlpha += alpha;
if (_verbose > 1)
cout << "Weak learner: " << pWeakHypothesis->getName()<< endl;
// Output the step-by-step information
pTrainingData->clearIndexSet();
printOutputInfo(pOutInfo, t, pTrainingData, pTestData, pWeakHypothesis);
// Updates the weights and returns the edge
//AlphaReal gamma = updateWeights(pTrainingData, pWeakHypothesis);
if (_verbose > 1)
{
cout << setprecision(5)
<< "--> Alpha = " << pWeakHypothesis->getAlpha() << endl
<< "--> Edge = " << edge << endl
<< "--> Energy = " << energy << endl
// << "--> ConstantEnergy = " << constantEnergy << endl
// << "--> difference = " << (energy - constantEnergy) << endl
;
}
// update the margins
//saveMargins();
updateMargins( pTrainingData, pWeakHypothesis );
// append the current weak learner to strong hypothesis file,
// that is, serialize it.
ss.appendHypothesis(t, pWeakHypothesis);
// Add it to the internal list of weak hypotheses
_foundHypotheses.push_back(pWeakHypothesis);
示例2: run
//.........这里部分代码省略.........
pWeakHypothesis->initLearningOptions(args);
//pTrainingData->clearIndexSet();
pWeakHypothesis->setTrainingData(pTrainingData);
float energy = pWeakHypothesis->run();
BaseLearner* pConstantWeakHypothesis;
if (_withConstantLearner) // check constant learner if user wants it
{
pConstantWeakHypothesis = pConstantWeakHypothesisSource->create() ;
pConstantWeakHypothesis->initLearningOptions(args);
pConstantWeakHypothesis->setTrainingData(pTrainingData);
float constantEnergy = pConstantWeakHypothesis->run();
}
//estimate edge
filter( pTrainingData, (int)(_Cn * log(t+2.0)), false );
float edge = pWeakHypothesis->getEdge() / 2.0;
if (_withConstantLearner) // check constant learner if user wants it
{
float constantEdge = pConstantWeakHypothesis->getEdge() / 2.0;
if ( constantEdge > edge )
{
delete pWeakHypothesis;
pWeakHypothesis = pConstantWeakHypothesis;
edge = constantEdge;
} else {
delete pConstantWeakHypothesis;
}
}
// calculate alpha
float alpha = 0.0;
alpha = 0.5 * log( ( 0.5 + edge ) / ( 0.5 - edge ) );
pWeakHypothesis->setAlpha( alpha );
if (_verbose > 1)
cout << "Weak learner: " << pWeakHypothesis->getName()<< endl;
// Output the step-by-step information
pTrainingData->clearIndexSet();
printOutputInfo(pOutInfo, t, pTrainingData, pTestData, pWeakHypothesis);
// Updates the weights and returns the edge
float gamma = updateWeights(pTrainingData, pWeakHypothesis);
if (_verbose > 1)
{
cout << setprecision(5)
<< "--> Alpha = " << pWeakHypothesis->getAlpha() << endl
<< "--> Edge = " << gamma << endl
<< "--> Energy = " << energy << endl
// << "--> ConstantEnergy = " << constantEnergy << endl
// << "--> difference = " << (energy - constantEnergy) << endl
;
}
// update the margins
updateMargins( pTrainingData, pWeakHypothesis );
// append the current weak learner to strong hypothesis file,
// that is, serialize it.
ss.appendHypothesis(t, pWeakHypothesis);
// Add it to the internal list of weak hypotheses
_foundHypotheses.push_back(pWeakHypothesis);
// check if the time limit has been reached
if (_maxTime > 0)
{
time( ¤tTime );
float diff = difftime(currentTime, startTime); // difftime is in seconds
diff /= 60; // = minutes
if (diff > _maxTime)
{
if (_verbose > 0)
cout << "Time limit of " << _maxTime
<< " minutes has been reached!" << endl;
break;
}
} // check for maxtime
delete pWeakHypothesis;
} // loop on iterations
/////////////////////////////////////////////////////////
// write the footer of the strong hypothesis file
ss.writeFooter();
// Free the two input data objects
if (pTrainingData)
delete pTrainingData;
if (pTestData)
delete pTestData;
if (pOutInfo)
delete pOutInfo;
if (_verbose > 0)
cout << "Learning completed." << endl;
}