Added a failed boolean to the fitness, for statistics... Average stat values are now computed from succesful fitness evaluations only

This commit is contained in:
okoenig 2004-06-14 17:07:25 +00:00
commit 4cfe47a8e5

View file

@ -42,20 +42,15 @@
for which fitness term (index) the average should be evaluated. for which fitness term (index) the average should be evaluated.
Only values of object where the failed boolean = false is set are counted. Only values of object where the failed boolean = false is set are counted.
*/ */
#ifdef _MSC_VER
template <class EOT> template <class EOT>
class eoAssembledFitnessAverageStat : public eoStat<EOT, EOT::Fitness> class eoAssembledFitnessAverageStat : public eoStat<EOT, double>
#else
template <class EOT>
class eoAssembledFitnessAverageStat : public eoStat<EOT, typename EOT::Fitness>
#endif
{ {
public : public :
typedef typename EOT::Fitness Fitness; typedef typename EOT::Fitness Fitness;
eoAssembledFitnessAverageStat(unsigned _whichTerm=0, std::string _description = "Average Fitness") eoAssembledFitnessAverageStat(unsigned _whichTerm=0, std::string _description = "Average Fitness")
: eoStat<EOT, Fitness>(Fitness(), _description), whichFitnessTerm(_whichTerm) {} : eoStat<EOT, double>(Fitness(), _description), whichFitnessTerm(_whichTerm) {}
virtual void operator()(const eoPop<EOT>& _pop){ virtual void operator()(const eoPop<EOT>& _pop){
@ -71,9 +66,7 @@ public :
} }
} }
value().clear(); value() = result / (double) count;
value() = result / _pop.size();
} }
private: private:
@ -86,26 +79,20 @@ private:
of type eoScalarAssembledFitness. Specify in the constructor, of type eoScalarAssembledFitness. Specify in the constructor,
for which fitness term (index) the value should be evaluated. for which fitness term (index) the value should be evaluated.
*/ */
#ifdef _MSC_VER
template <class EOT> template <class EOT>
class eoAssembledFitnessBestStat : public eoStat<EOT, EOT::Fitness> class eoAssembledFitnessBestStat : public eoStat<EOT, double>
#else
template <class EOT>
class eoAssembledFitnessBestStat : public eoStat<EOT, typename EOT::Fitness>
#endif
{ {
public : public :
typedef typename EOT::Fitness Fitness; typedef typename EOT::Fitness Fitness;
eoAssembledFitnessBestStat(unsigned _whichTerm=0, std::string _description = "Best Fitness") eoAssembledFitnessBestStat(unsigned _whichTerm=0, std::string _description = "Best Fitness")
: eoStat<EOT, Fitness>(Fitness(), _description), whichFitnessTerm(_whichTerm) {} : eoStat<EOT, double>(Fitness(), _description), whichFitnessTerm(_whichTerm) {}
virtual void operator()(const eoPop<EOT>& _pop){ virtual void operator()(const eoPop<EOT>& _pop){
if ( whichFitnessTerm >= _pop[0].fitness().size() ) if ( whichFitnessTerm >= _pop[0].fitness().size() )
throw std::logic_error("Fitness term requested out of range"); throw std::logic_error("Fitness term requested out of range");
value().clear();
value() = _pop.best_element().fitness()[whichFitnessTerm]; value() = _pop.best_element().fitness()[whichFitnessTerm];
} }