本文整理汇总了C++中Stats::clearItems方法的典型用法代码示例。如果您正苦于以下问题:C++ Stats::clearItems方法的具体用法?C++ Stats::clearItems怎么用?C++ Stats::clearItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stats
的用法示例。
在下文中一共展示了Stats::clearItems方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: calculateStatsDeme
void StatsCalcFitnessNMSEOp::calculateStatsDeme(Stats &outStats, Deme &ioDeme, Context &ioContext) const {
Beagle_StackTraceBeginM();
outStats.clear();
outStats.clearItems();
int outputs = mConfig->getOutputs().size();
outStats.addItem("processed", ioContext.getProcessedDeme());
outStats.addItem("total-processed", ioContext.getTotalProcessedDeme());
if(ioDeme.size() == 0) {
outStats.setGenerationValues(Beagle::string("deme")+uint2str(ioContext.getDemeIndex()+1),
ioContext.getGeneration(), 0, true);
outStats.resize(3+outputs*2);
outStats[0].mId = "NMSE";
outStats[0].mAvg = 0.0;
outStats[0].mStd = 0.0;
outStats[0].mMax = 0.0;
outStats[0].mMin = 0.0;
outStats[1].mId = "treedepth";
outStats[1].mAvg = 0.0;
outStats[1].mStd = 0.0;
outStats[1].mMax = 0.0;
outStats[1].mMin = 0.0;
outStats[2].mId = "treesize";
outStats[2].mAvg = 0.0;
outStats[2].mStd = 0.0;
outStats[2].mMax = 0.0;
outStats[2].mMin = 0.0;
for(int i=0; i<outputs; ++i) {
int nr = 3 + i*2;
outStats[nr].mId = "y" + int2str(i) + "-NMSE";
outStats[nr].mAvg = 0.0;
outStats[nr].mStd = 0.0;
outStats[nr].mMax = 0.0;
outStats[nr].mMin = 0.0;
++nr;
outStats[nr].mId = "y" + int2str(i) + "-MSE";
outStats[nr].mAvg = 0.0;
outStats[nr].mStd = 0.0;
outStats[nr].mMax = 0.0;
outStats[nr].mMin = 0.0;
}
return;
}
const GP::Deme& gpDeme = castObjectT<const GP::Deme&>(ioDeme);
const FitnessNMSE::Handle firstIndivFitness = castHandleT<FitnessNMSE>(ioDeme[0]->getFitness());
if(ioDeme.size() == 1) {
outStats.setGenerationValues(Beagle::string("deme")+uint2str(ioContext.getDemeIndex()+1),
ioContext.getGeneration(), 1, true);
outStats.resize(3+outputs*2);
outStats[0].mId = "NMSE";
outStats[0].mAvg = firstIndivFitness->getNMSE();
outStats[0].mStd = 0.0;
outStats[0].mMax = firstIndivFitness->getNMSE();
outStats[0].mMin = firstIndivFitness->getNMSE();
outStats[1].mId = "treedepth";
outStats[1].mAvg = gpDeme[0]->getMaxTreeDepth();
outStats[1].mStd = 0.0;
outStats[1].mMax = outStats[1].mAvg;
outStats[1].mMin = outStats[1].mAvg;
outStats[2].mId = "treesize";
outStats[2].mAvg = gpDeme[0]->getTotalNodes();
outStats[2].mStd = 0.0;
outStats[2].mMax = outStats[2].mAvg;
outStats[2].mMin = outStats[2].mAvg;
for(int i=0; i<outputs; ++i) {
int nr = 3 + i*2;
double nmse = (*firstIndivFitness)[i].nmse;
double mse = (*firstIndivFitness)[i].mse;
outStats[nr].mId = "y" + int2str(i) + "-NMSE";
outStats[nr].mAvg = nmse;
outStats[nr].mStd = 0.0;
outStats[nr].mMax = nmse;
outStats[nr].mMin = nmse;
++nr;
outStats[nr].mId = "y" + int2str(i) + "-MSE";
outStats[nr].mAvg = mse;
outStats[nr].mStd = 0.0;
outStats[nr].mMax = mse;
outStats[nr].mMin = mse;
}
return;
}
double sum = firstIndivFitness->getNMSE();
double pow2sum = pow2Of<double>(sum);
double max = sum;
double min = sum;
std::vector<double> sumNMSE(outputs, 0);
//.........这里部分代码省略.........
示例2: calculateStatsVivarium
/*!
* \brief Calculate statistics of a given vivarium.
* \param outStats Computed stats of the deme.
* \param ioVivarium Vivarium to evaluate the statistics.
* \param ioContext Context of the evolution.
*/
void StatsCalculateOp::calculateStatsVivarium(Stats& outStats,
Vivarium& ioVivarium,
Context& ioContext) const
{
Beagle_StackTraceBeginM();
outStats.clear();
outStats.clearItems();
unsigned int lPopSize = 0;
for(unsigned int i=0; i<ioVivarium.size(); ++i) {
Beagle::Stats::Handle lDemeStats = ioVivarium[i]->getStats();
Beagle_NonNullPointerAssertM(lDemeStats);
lPopSize += lDemeStats->getPopSize();
}
outStats.setGenerationValues("vivarium", ioContext.getGeneration(), lPopSize, true);
outStats.addItem("processed", ioContext.getProcessedVivarium());
outStats.addItem("total-processed", ioContext.getTotalProcessedVivarium());
if(ioVivarium.size() == 0) return;
outStats.resize(ioVivarium[0]->getStats()->size());
for(unsigned int i=0; i<outStats.size(); ++i) {
double lSumXi = 0.0;
double lSumXiPow2 = 0.0;
double lMax = (*ioVivarium[0]->getStats())[i].mMax;
double lMin = (*ioVivarium[0]->getStats())[i].mMin;
for(unsigned int j=0; j<ioVivarium.size(); ++j) {
Beagle_AssertM(outStats.size() == ioVivarium[j]->getStats()->size());
const Measure& lMeasure = (*ioVivarium[j]->getStats())[i];
unsigned int lDemeSize = ioVivarium[j]->getStats()->getPopSize();
if(lDemeSize != 0) {
double lSumFit = lMeasure.mAvg * lDemeSize;
double lTmpVar1 = pow2Of<double>(lSumFit) / lDemeSize;
double lTmpVar2 = pow2Of<double>(lMeasure.mStd) * (lDemeSize-1);
lSumXi += lSumFit;
lSumXiPow2 += lTmpVar1 + lTmpVar2;
lMax = maxOf<double>(lMax, lMeasure.mMax);
lMin = minOf<double>(lMin, lMeasure.mMin);
}
}
outStats[i].mID = (*ioVivarium[0]->getStats())[i].mID;
if(lPopSize == 0) {
outStats[i].mAvg = 0.0;
outStats[i].mStd = 0.0;
outStats[i].mMax = 0.0;
outStats[i].mMin = 0.0;
} else if(lPopSize == 1) {
outStats[i].mAvg = lSumXi;
outStats[i].mStd = 0.0;
outStats[i].mMax = lMax;
outStats[i].mMin = lMin;
} else {
double lAverage = lSumXi / lPopSize;
double lVariance =
lSumXiPow2 - (pow2Of<double>(lAverage*((double)lPopSize)) / ((double)lPopSize));
double lStdError = sqrt(lVariance / (lPopSize - 1));
outStats[i].mAvg = lAverage;
outStats[i].mStd = lStdError;
outStats[i].mMax = lMax;
outStats[i].mMin = lMin;
}
}
Beagle_StackTraceEndM("void StatsCalculateOp::calculateStatsVivarium(Stats& outStats, Vivarium& ioVivarium, Context& ioContext) const");
}