⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fitnesskoza.cpp

📁 非常好的进化算法EC 实现平台 可以实现多种算法 GA GP
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* *  Open BEAGLE *  Copyright (C) 2001-2005 by Christian Gagne and Marc Parizeau * *  This library is free software; you can redistribute it and/or *  modify it under the terms of the GNU Lesser General Public *  License as published by the Free Software Foundation; either *  version 2.1 of the License, or (at your option) any later version. * *  This library is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *  Lesser General Public License for more details. * *  You should have received a copy of the GNU Lesser General Public *  License along with this library; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * *  Contact: *  Laboratoire de Vision et Systemes Numeriques *  Departement de genie electrique et de genie informatique *  Universite Laval, Quebec, Canada, G1K 7P4 *  http://vision.gel.ulaval.ca * *//*! *  \file   beagle/GP/src/FitnessKoza.cpp *  \brief  Source code of class FitnessKoza. *  \author Christian Gagne *  \author Marc Parizeau *  $Revision: 1.12 $ *  $Date: 2005/10/04 09:32:52 $ */#include "beagle/GP.hpp"#include <cmath>#include <cfloat>#include <algorithm>using namespace Beagle;/*! *  \brief Default construct a Koza's fitness object. */GP::FitnessKoza::FitnessKoza() :  FitnessSimple(),  mAdjustedFitness(0.),  mStandardizedFitness(0.),  mRawFitness(0.),  mHits(0){ }/*! *  \brief Construct a valid Koza's fitness object. *  \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. */GP::FitnessKoza::FitnessKoza(float inNormalizedFitness,                             float inAdjustedFitness,                             float inStandardizedFitness,                             float inRawFitness,                             unsigned int inHits){  Beagle_StackTraceBeginM();  setFitness(inNormalizedFitness,             inAdjustedFitness,             inStandardizedFitness,             inRawFitness,             inHits);  Beagle_StackTraceEndM("GP::FitnessKoza::FitnessKoza(float inNormalizedFitness, float inAdjustedFitness, float inStandardizedFitness, float inRawFitness, unsigned int inHits)");}/*! *  \brief Calculate statistics of a given deme. *  \param ioDeme Deme to evalute the statistics. *  \param ioContext Context of the evolution. *  \return Handle to a generationnal statistics of the given deme. */void GP::FitnessKoza::calculateStats(Beagle::Deme& ioDeme, Beagle::Context& ioContext) const{  Beagle_StackTraceBeginM();  if(ioDeme.size() == 0) {    Stats& lStats = *ioDeme.getStats();    lStats.setGenerationValues(string("deme")+uint2str(ioContext.getDemeIndex()+1),                               ioContext.getGeneration(),                               0,                               true);    lStats.resize(7);    lStats[0].mId = "normalized";    lStats[0].mAvg = 0.0;    lStats[0].mStd = 0.0;    lStats[0].mMax = 0.0;    lStats[0].mMin = 0.0;    lStats[1].mId = "adjusted";    lStats[1].mAvg = 0.0;    lStats[1].mStd = 0.0;    lStats[1].mMax = 0.0;    lStats[1].mMin = 0.0;    lStats[2].mId = "standardized";    lStats[2].mAvg = 0.0;    lStats[2].mStd = 0.0;    lStats[2].mMax = 0.0;    lStats[2].mMin = 0.0;    lStats[3].mId = "raw";    lStats[3].mAvg = 0.0;    lStats[3].mStd = 0.0;    lStats[3].mMax = 0.0;    lStats[3].mMin = 0.0;    lStats[4].mId = "hits";    lStats[4].mAvg = 0.0;    lStats[4].mStd = 0.0;    lStats[4].mMax = 0.0;    lStats[4].mMin = 0.0;    lStats[5].mId = "treedepth";    lStats[5].mAvg = 0.0;    lStats[5].mStd = 0.0;    lStats[5].mMax = 0.0;    lStats[5].mMin = 0.0;    lStats[6].mId = "treesize";    lStats[6].mAvg = 0.0;    lStats[6].mStd = 0.0;    lStats[6].mMax = 0.0;    lStats[6].mMin = 0.0;    return;  }  const GP::Deme&    lGPDeme    = castObjectT<const GP::Deme&>(ioDeme);  const GP::FitnessKoza::Handle lFirstIndivFitness =    castHandleT<GP::FitnessKoza>(lGPDeme[0]->getFitness());  double lSumNrm         = (double)lFirstIndivFitness->getNormalizedFitness();  double lPow2SumNrm     = pow2Of<double>(lSumNrm);  double lMaxNrm         = (double)lFirstIndivFitness->getNormalizedFitness();  double lMinNrm         = (double)lFirstIndivFitness->getNormalizedFitness();  double lSumAdj         = (double)lFirstIndivFitness->getAdjustedFitness();  double lPow2SumAdj     = pow2Of<double>(lSumAdj);  double lMaxAdj         = (double)lFirstIndivFitness->getAdjustedFitness();  double lMinAdj         = (double)lFirstIndivFitness->getAdjustedFitness();  double lSumStd         = (double)lFirstIndivFitness->getStandardizedFitness();  double lPow2SumStd     = pow2Of<double>(lSumStd);  double lMaxStd         = (double)lFirstIndivFitness->getStandardizedFitness();  double lMinStd         = (double)lFirstIndivFitness->getStandardizedFitness();  double lSumRaw         = (double)lFirstIndivFitness->getRawFitness();  double lPow2SumRaw     = pow2Of<double>(lSumRaw);  double  lMaxRaw        = (double)lFirstIndivFitness->getRawFitness();  double lMinRaw         = (double)lFirstIndivFitness->getRawFitness();  double lSumHit         = (double)lFirstIndivFitness->getHits();  double lPow2SumHit     = pow2Of<double>(lSumHit);  unsigned int lMaxHit   = lFirstIndivFitness->getHits();  unsigned int lMinHit   = lFirstIndivFitness->getHits();  unsigned int lMaxDepth = lGPDeme[0]->getMaxTreeDepth();  unsigned int lMinDepth = lMaxDepth;  double lSumDepth       = (double)lMaxDepth;  double lPow2SumDepth   = pow2Of<double>(lSumDepth);  unsigned int lMaxSize  = lGPDeme[0]->getTotalNodes();  unsigned int lMinSize  = lMaxSize;  double lSumSize        = (double)lMaxSize;  double lPow2SumSize    = pow2Of<double>(lSumSize);    for(unsigned int i=1; i<lGPDeme.size(); i++) {    const GP::FitnessKoza::Handle lIndivFitness =      castHandleT<GP::FitnessKoza>(lGPDeme[i]->getFitness());    lSumNrm     += (double)lIndivFitness->getNormalizedFitness();    lPow2SumNrm += pow2Of<double>((double)lIndivFitness->getNormalizedFitness());    lSumAdj     += (double)lIndivFitness->getAdjustedFitness();    lPow2SumAdj += pow2Of<double>((double)lIndivFitness->getAdjustedFitness());    lSumStd     += (double)lIndivFitness->getStandardizedFitness();    lPow2SumStd += pow2Of<double>(lIndivFitness->getStandardizedFitness());    lSumRaw     += (double)lIndivFitness->getRawFitness();    lPow2SumRaw += pow2Of<double>((double)lIndivFitness->getRawFitness());    lSumHit     += (double)lIndivFitness->getHits();    lPow2SumHit += pow2Of<double>((double)lIndivFitness->getHits());    if(((double)lIndivFitness->getNormalizedFitness()) > lMaxNrm) {      lMaxNrm = lIndivFitness->getNormalizedFitness();      lMaxAdj = lIndivFitness->getAdjustedFitness();      lMaxStd = lIndivFitness->getStandardizedFitness();      lMaxRaw = lIndivFitness->getRawFitness();      lMaxHit = lIndivFitness->getHits();    }    if(((double)lIndivFitness->getNormalizedFitness()) < lMinNrm) {      lMinNrm = lIndivFitness->getNormalizedFitness();      lMinAdj = lIndivFitness->getAdjustedFitness();      lMinStd = lIndivFitness->getStandardizedFitness();      lMinRaw = lIndivFitness->getRawFitness();      lMinHit = lIndivFitness->getHits();    }    unsigned int lTmpDepth = lGPDeme[i]->getMaxTreeDepth();    lSumDepth     += (double)lTmpDepth;    lPow2SumDepth += pow2Of<double>((double)lTmpDepth);    lMaxDepth     =  maxOf(lMaxDepth, lTmpDepth);    lMinDepth     =  minOf(lMinDepth, lTmpDepth);    unsigned int lTmpSize = lGPDeme[i]->getTotalNodes();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -