added eoAssembledFitnessStat.h to implement Best and Avg Stat for eoScalarFitnessAssembled
This commit is contained in:
parent
45e3b86bcb
commit
c39b241413
3 changed files with 116 additions and 4 deletions
|
|
@ -93,19 +93,19 @@ eoCheckPoint<EOT>& do_make_checkpoint_assembled(eoParser& _parser, eoState& _sta
|
|||
// ---------------------------
|
||||
|
||||
// average vals
|
||||
std::vector<eoAverageStat<EOT>* > avgvals( nTerms );
|
||||
std::vector<eoAssembledFitnessAverageStat<EOT>* > avgvals( nTerms );
|
||||
for (unsigned i=0; i < nTerms; ++i){
|
||||
std::string descr = "Avg. of " + fitness_descriptions[i];
|
||||
avgvals[i] = new eoAverageStat<EOT>(i, descr);
|
||||
avgvals[i] = new eoAssembledFitnessAverageStat<EOT>(i, descr);
|
||||
_state.storeFunctor( avgvals[i] );
|
||||
checkpoint->add( *avgvals[i] );
|
||||
}
|
||||
|
||||
// best vals
|
||||
std::vector<eoBestFitnessStat<EOT>* > bestvals( nTerms );
|
||||
std::vector<eoAssembledFitnessBestStat<EOT>* > bestvals( nTerms );
|
||||
for (unsigned j=0; j < nTerms; ++j){
|
||||
std::string descr = fitness_descriptions[j] + " of best ind.";
|
||||
bestvals[j] = new eoBestFitnessStat<EOT>(j, descr);
|
||||
bestvals[j] = new eoAssembledFitnessBestStat<EOT>(j, descr);
|
||||
_state.storeFunctor( bestvals[j] );
|
||||
checkpoint->add( *bestvals[j] );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include <utils/eoCheckPoint.h>
|
||||
#include <utils/eoStat.h>
|
||||
#include <utils/eoScalarFitnessStat.h>
|
||||
#include <utils/eoAssembledFitnessStat.h>
|
||||
#include <utils/eoFDCStat.h>
|
||||
#include <utils/eoMOFitnessStat.h>
|
||||
#include <utils/eoPopStat.h>
|
||||
|
|
|
|||
111
eo/src/utils/eoAssembledFitnessStat.h
Normal file
111
eo/src/utils/eoAssembledFitnessStat.h
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoAssembledFitnessStat.h
|
||||
// Marc Wintermantel & Oliver Koenig
|
||||
// IMES-ST@ETHZ.CH
|
||||
// April 2003
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoStat.h
|
||||
// (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000
|
||||
/*
|
||||
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 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: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
mkeijzer@dhi.dk
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _eoAssembledFitnessStat_h
|
||||
#define _eoAssembledFitnessStat_h
|
||||
|
||||
#include <utils/eoStat.h>
|
||||
#include <eoScalarFitnessAssembled.h>
|
||||
|
||||
/**
|
||||
Average fitness values of a population, where the fitness is
|
||||
of type eoScalarAssembledFitness. Specify in the constructor,
|
||||
for which fitness term (index) the average should be evaluated.
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
template <class EOT>
|
||||
class eoAssembledFitnessAverageStat : public eoStat<EOT, EOT::Fitness>
|
||||
#else
|
||||
template <class EOT>
|
||||
class eoAssembledFitnessAverageStat : public eoStat<EOT, typename EOT::Fitness>
|
||||
#endif
|
||||
{
|
||||
public :
|
||||
|
||||
typedef typename EOT::Fitness Fitness;
|
||||
|
||||
eoAssembledFitnessAverageStat(unsigned _whichTerm=0, std::string _description = "Average Fitness")
|
||||
: eoStat<EOT, Fitness>(Fitness(), _description), whichFitnessTerm(_whichTerm) {}
|
||||
|
||||
virtual void operator()(const eoPop<EOT>& _pop){
|
||||
|
||||
if ( whichFitnessTerm >= _pop[0].fitness().size() )
|
||||
throw std::logic_error("Fitness term requested out of range");
|
||||
|
||||
double result =0.0;
|
||||
for (typename eoPop<EOT>::const_iterator it = _pop.begin(); it != _pop.end(); ++it)
|
||||
result+= it->fitness()[whichFitnessTerm];
|
||||
|
||||
value().clear();
|
||||
value() = result / _pop.size();
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
// Store an index of the fitness term to be evaluated in eoScalarFitnessAssembled
|
||||
unsigned whichFitnessTerm;
|
||||
};
|
||||
|
||||
/**
|
||||
Fitness values of best individuum in a population, where the fitness is
|
||||
of type eoScalarAssembledFitness. Specify in the constructor,
|
||||
for which fitness term (index) the value should be evaluated.
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
template <class EOT>
|
||||
class eoAssembledFitnessBestStat : public eoStat<EOT, EOT::Fitness>
|
||||
#else
|
||||
template <class EOT>
|
||||
class eoAssembledFitnessBestStat : public eoStat<EOT, typename EOT::Fitness>
|
||||
#endif
|
||||
{
|
||||
public :
|
||||
typedef typename EOT::Fitness Fitness;
|
||||
|
||||
eoAssembledFitnessBestStat(unsigned _whichTerm=0, std::string _description = "Best Fitness")
|
||||
: eoStat<EOT, Fitness>(Fitness(), _description), whichFitnessTerm(_whichTerm) {}
|
||||
|
||||
virtual void operator()(const eoPop<EOT>& _pop){
|
||||
|
||||
if ( whichFitnessTerm >= _pop[0].fitness().size() )
|
||||
throw std::logic_error("Fitness term requested out of range");
|
||||
|
||||
value().clear();
|
||||
value() = _pop.best_element().fitness()[whichFitnessTerm];
|
||||
}
|
||||
|
||||
private:
|
||||
// Store an index of the fitness term to be evaluated in eoScalarFitnessAssembled
|
||||
unsigned whichFitnessTerm;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in a new issue