📄 fitnesskoza.cpp
字号:
lSumSize += (double)lTmpSize; lPow2SumSize += pow2Of<double>((double)lTmpSize); lMaxSize = maxOf(lMaxSize, lTmpSize); lMinSize = minOf(lMinSize, lTmpSize); } double lNrmAverage = (lSumNrm / lGPDeme.size()); double lNrmStdError = (lPow2SumNrm - (pow2Of<double>(lSumNrm) / lGPDeme.size())) / (lGPDeme.size() - 1); lNrmStdError = sqrt(lNrmStdError); double lAdjAverage = (lSumAdj / lGPDeme.size()); double lAdjStdError = (lPow2SumAdj - (pow2Of<double>(lSumAdj) / lGPDeme.size())) / (lGPDeme.size() - 1); lAdjStdError = sqrt(lAdjStdError); double lStdAverage = (lSumStd / lGPDeme.size()); double lStdStdError = (lPow2SumStd - (pow2Of<double>(lSumStd) / lGPDeme.size())) / (lGPDeme.size() - 1); lStdStdError = sqrt(lStdStdError); double lRawAverage = (lSumRaw / lGPDeme.size()); double lRawStdError = (lPow2SumRaw - (pow2Of<double>(lSumRaw) / lGPDeme.size())) / (lGPDeme.size() - 1); lRawStdError = sqrt(lRawStdError); double lHitAverage = (lSumHit / lGPDeme.size()); double lHitStdError = (lPow2SumHit - (pow2Of<double>(lSumHit) / lGPDeme.size())) / (lGPDeme.size() - 1); lHitStdError = sqrt(lHitStdError); double lDepthAverage = (lSumDepth / lGPDeme.size()); double lDepthStdError = (lPow2SumDepth - (pow2Of<double>(lSumDepth) / lGPDeme.size())) / (lGPDeme.size() - 1); lDepthStdError = sqrt(lDepthStdError); double lSizeAverage = (lSumSize / lGPDeme.size()); double lSizeStdError = (lPow2SumSize - (pow2Of<double>(lSumSize) / lGPDeme.size())) / (lGPDeme.size() - 1); lSizeStdError = sqrt(lSizeStdError); Stats& lStats = *ioDeme.getStats(); lStats.setGenerationValues(string("deme")+uint2str(ioContext.getDemeIndex()+1), ioContext.getGeneration(), ioDeme.size(), true); lStats.resize(7); lStats[0].mId = "normalized"; lStats[0].mAvg = lNrmAverage; lStats[0].mStd = lNrmStdError; lStats[0].mMax = lMaxNrm; lStats[0].mMin = lMinNrm; lStats[1].mId = "adjusted"; lStats[1].mAvg = lAdjAverage; lStats[1].mStd = lAdjStdError; lStats[1].mMax = lMaxAdj; lStats[1].mMin = lMinAdj; lStats[2].mId = "standardized"; lStats[2].mAvg = lStdAverage; lStats[2].mStd = lStdStdError; lStats[2].mMax = lMaxStd; lStats[2].mMin = lMinStd; lStats[3].mId = "raw"; lStats[3].mAvg = lRawAverage; lStats[3].mStd = lRawStdError; lStats[3].mMax = lMaxRaw; lStats[3].mMin = lMinRaw; lStats[4].mId = "hits"; lStats[4].mAvg = lHitAverage; lStats[4].mStd = lHitStdError; lStats[4].mMax = (float)lMaxHit; lStats[4].mMin = (float)lMinHit; lStats[5].mId = "treedepth"; lStats[5].mAvg = lDepthAverage; lStats[5].mStd = lDepthStdError; lStats[5].mMax = (float)lMaxDepth; lStats[5].mMin = (float)lMinDepth; lStats[6].mId = "treesize"; lStats[6].mAvg = lSizeAverage; lStats[6].mStd = lSizeStdError; lStats[6].mMax = (float)lMaxSize; lStats[6].mMin = (float)lMinSize; Beagle_StackTraceEndM("void GP::FitnessKoza::calculateStats(Beagle::Deme& ioDeme, Beagle::Context& ioContext) const");}/*! * \brief Read a Koza's fitness from a XML subtree. * \param inIter XML iterator to use to read the fitness values. */void GP::FitnessKoza::read(PACC::XML::ConstIterator inIter){ Beagle_StackTraceBeginM(); if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!="Fitness")) throw Beagle_IOExceptionNodeM(*inIter, "tag <Fitness> expected!"); string lType = inIter->getAttribute("type").c_str(); if(lType != "koza") throw Beagle_IOExceptionNodeM(*inIter, "fitness type mismatch!"); for(PACC::XML::ConstIterator lChild=inIter->getFirstChild(); lChild; ++lChild) { if(lChild->getType() == PACC::XML::eData) { if(lChild->getValue() == "Normalized") { PACC::XML::ConstIterator lChild2 = lChild->getFirstChild(); if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "no normalized fitness value present!"); if(lChild2->getType() != PACC::XML::eString) throw Beagle_IOExceptionNodeM(*lChild2, "no normalized fitness value present!"); mFitness = str2dbl(lChild2->getValue().c_str()); } else if(lChild->getValue() == "Adjusted") { PACC::XML::ConstIterator lChild2 = lChild->getFirstChild(); if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "no adjusted fitness value present!"); if(lChild2->getType() != PACC::XML::eString) throw Beagle_IOExceptionNodeM(*lChild2, "no adjusted fitness value present!"); mAdjustedFitness = str2dbl(lChild2->getValue().c_str()); } else if(lChild->getValue() == "Standardized") { PACC::XML::ConstIterator lChild2 = lChild->getFirstChild(); if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "no standardized fitness value present!"); if(lChild2->getType() != PACC::XML::eString) throw Beagle_IOExceptionNodeM(*lChild2, "no standardized fitness value present!"); mStandardizedFitness = str2dbl(lChild2->getValue().c_str()); } else if(lChild->getValue() == "Raw") { PACC::XML::ConstIterator lChild2 = lChild->getFirstChild(); if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "no raw fitness value present!"); if(lChild2->getType() != PACC::XML::eString) throw Beagle_IOExceptionNodeM(*lChild2, "no raw fitness value present!"); mRawFitness = str2dbl(lChild2->getValue().c_str()); } else if(lChild->getValue() == "Hits") { PACC::XML::ConstIterator lChild2 = lChild->getFirstChild(); if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "no hits value present!"); if(lChild2->getType() != PACC::XML::eString) throw Beagle_IOExceptionNodeM(*lChild2, "no hits value present!"); mHits = str2uint(lChild2->getValue().c_str()); } } } Beagle_StackTraceEndM("void GP::FitnessKoza::read(PACC::XML::ConstIterator inIter)");}/*! * \brief Set the fitness value and validity. * \param inNormalizedFitness Normalized fitness value. * \param inAdjustedFitness Adjusted fitness value. * \param inStandardizedFitness Standardized fitness value. * \param inRawFitness Raw fitness value. * \param inHits Number of hits. */void GP::FitnessKoza::setFitness(float inNormalizedFitness, float inAdjustedFitness, float inStandardizedFitness, float inRawFitness, unsigned int inHits){ Beagle_StackTraceBeginM(); if(isFinite(inNormalizedFitness)) mFitness = inNormalizedFitness; else mFitness = FLT_MIN; if(isFinite(inAdjustedFitness)) mAdjustedFitness = inAdjustedFitness; else mAdjustedFitness = 0.; if(isFinite(inStandardizedFitness)) mStandardizedFitness = inStandardizedFitness; else mStandardizedFitness = 0.; if(isFinite(inRawFitness)) mRawFitness = inRawFitness; else mRawFitness = 0.; mHits = inHits; setValid(); Beagle_StackTraceEndM("void GP::FitnessKoza::setFitness(float inNormalizedFitness, float inAdjustedFitness, float inStandardizedFitness, float inRawFitness, unsigned int inHits)");}/*! * \brief Write a Koza's fitness into a Beagle XML streamer. * \param ioStreamer XML streamer to use to write the fitness values. * \param inIndent Whether XML output should be indented. */void GP::FitnessKoza::write(PACC::XML::Streamer& ioStreamer, bool inIndent) const{ Beagle_StackTraceBeginM(); ioStreamer.openTag("Fitness", inIndent); ioStreamer.insertAttribute("type", "koza"); ioStreamer.openTag("Normalized", false); ioStreamer.insertStringContent(dbl2str(mFitness).c_str()); ioStreamer.closeTag(); ioStreamer.openTag("Adjusted", false); ioStreamer.insertStringContent(dbl2str(mAdjustedFitness).c_str()); ioStreamer.closeTag(); ioStreamer.openTag("Standardized", false); ioStreamer.insertStringContent(dbl2str(mStandardizedFitness).c_str()); ioStreamer.closeTag(); ioStreamer.openTag("Raw", false); ioStreamer.insertStringContent(dbl2str(mRawFitness).c_str()); ioStreamer.closeTag(); ioStreamer.openTag("Hits", false); ioStreamer.insertStringContent(uint2str(mHits).c_str()); ioStreamer.closeTag(); ioStreamer.closeTag(); Beagle_StackTraceEndM("void GP::FitnessKoza::write(PACC::XML::Streamer& ioStreamer, bool inIndent) const");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -