/*! * \brief Copy vivarium using the system. * \param inOriginal Vivarium to copy into current one. * \param ioSystem Evolutionary system. */ void Vivarium::copy(const Vivarium& inOriginal, System& ioSystem) { Beagle_StackTraceBeginM(); const Factory& lFactory = ioSystem.getFactory(); // Copy members mMemberMap.clear(); for(MemberMap::const_iterator lIterMap=inOriginal.mMemberMap.begin(); lIterMap!=inOriginal.mMemberMap.end(); ++lIterMap) { Member::Handle lOrigMember = castHandleT<Member>(lIterMap->second); const std::string& lMemberType = lOrigMember->getType(); Member::Alloc::Handle lMemberAlloc = castHandleT<Member::Alloc>(lFactory.getAllocator(lMemberType)); Member::Handle lMember = castHandleT<Member>(lMemberAlloc->allocate()); lMember->copy(*lOrigMember, ioSystem); mMemberMap[lIterMap->first] = lMember; } // Copy demes resize(inOriginal.size()); for(unsigned int i=0; i<inOriginal.size(); ++i) { const std::string& lDemeTypeName = inOriginal[i]->getType(); Deme::Alloc::Handle lDemeAlloc = castHandleT<Deme::Alloc>(lFactory.getAllocator(lDemeTypeName)); Deme::Handle lDeme = castHandleT<Deme>(lDemeAlloc->allocate()); lDeme->copy(*inOriginal[i], ioSystem); (*this)[i] = lDeme; } Beagle_StackTraceEndM(); }
/*! * \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"); }