From 4cfe47a8e512b76038fe0eed90d00ef46e0716bf Mon Sep 17 00:00:00 2001 From: okoenig Date: Mon, 14 Jun 2004 17:07:25 +0000 Subject: [PATCH] Added a failed boolean to the fitness, for statistics... Average stat values are now computed from succesful fitness evaluations only --- eo/src/utils/eoAssembledFitnessStat.h | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/eo/src/utils/eoAssembledFitnessStat.h b/eo/src/utils/eoAssembledFitnessStat.h index 6a064b1e..c44bb7b4 100644 --- a/eo/src/utils/eoAssembledFitnessStat.h +++ b/eo/src/utils/eoAssembledFitnessStat.h @@ -42,20 +42,15 @@ for which fitness term (index) the average should be evaluated. Only values of object where the failed boolean = false is set are counted. */ -#ifdef _MSC_VER template -class eoAssembledFitnessAverageStat : public eoStat -#else -template -class eoAssembledFitnessAverageStat : public eoStat -#endif +class eoAssembledFitnessAverageStat : public eoStat { public : typedef typename EOT::Fitness Fitness; eoAssembledFitnessAverageStat(unsigned _whichTerm=0, std::string _description = "Average Fitness") - : eoStat(Fitness(), _description), whichFitnessTerm(_whichTerm) {} + : eoStat(Fitness(), _description), whichFitnessTerm(_whichTerm) {} virtual void operator()(const eoPop& _pop){ @@ -66,14 +61,12 @@ public : unsigned count = 0; for (typename eoPop::const_iterator it = _pop.begin(); it != _pop.end(); ++it){ if ( it->fitness().failed == false ){ - result+= it->fitness()[whichFitnessTerm]; - ++count; + result+= it->fitness()[whichFitnessTerm]; + ++count; } } - value().clear(); - value() = result / _pop.size(); - + value() = result / (double) count; } private: @@ -86,26 +79,20 @@ private: of type eoScalarAssembledFitness. Specify in the constructor, for which fitness term (index) the value should be evaluated. */ -#ifdef _MSC_VER template -class eoAssembledFitnessBestStat : public eoStat -#else -template -class eoAssembledFitnessBestStat : public eoStat -#endif +class eoAssembledFitnessBestStat : public eoStat { public : typedef typename EOT::Fitness Fitness; eoAssembledFitnessBestStat(unsigned _whichTerm=0, std::string _description = "Best Fitness") - : eoStat(Fitness(), _description), whichFitnessTerm(_whichTerm) {} + : eoStat(Fitness(), _description), whichFitnessTerm(_whichTerm) {} virtual void operator()(const eoPop& _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]; }