From 188d1b4c566276811dd143af7036323ea8b7911c Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Fri, 23 Nov 2012 16:52:35 +0100 Subject: [PATCH] REMOVE the generic fitness templates in eoSecondMomentStats in favor of scalar ones ; comment out old unused code --- eo/src/utils/eoStat.h | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/eo/src/utils/eoStat.h b/eo/src/utils/eoStat.h index c932fb353..fd26ec228 100644 --- a/eo/src/utils/eoStat.h +++ b/eo/src/utils/eoStat.h @@ -32,6 +32,7 @@ Contact: http://eodev.sourceforge.net #ifndef _eoStat_h #define _eoStat_h +#include #include // accumulate #include @@ -176,13 +177,24 @@ private : }; /** - Average fitness + Std. dev. of a population, fitness needs to be scalar. + Average fitness + Std. dev. of a population, fitness HAVE TO BE to be scalar. */ template -class eoSecondMomentStats : public eoStat > +// FIXME find a way to use generic Fitness types instead of scala fitness here : +// class eoSecondMomentStats : public eoStat > + // Here, I failed to find a way to overload eoValueParam::getValue and setValue, + // because there is no way to use the partial specializations located in eoParam.h + // Indeed, eoValueParam is templatized on a ValueType, but the getValue signature does not + // contain this type. + // Thus, in order to use partial specializations the user would have to specify getValue(), + // which is not the case in most of the existing code. + // Overloading getValue in this class does not seems to work, the call falls to eoValueParam::getValue + // and fails on the output stream. +class eoSecondMomentStats : public eoStat > { public : - typedef typename EOT::Fitness FitT; + // typedef typename EOT::Fitness FitT; + typedef double FitT; using eoStat >::value; typedef std::pair SquarePair; @@ -209,9 +221,11 @@ public : value().second = sqrt( (result.second - n * value().first * value().first) / (n - 1.0)); // stdev } - virtual std::string className(void) const { return "eoSecondMomentStats"; } + virtual std::string className(void) const { return "eoSecondMomentStats"; } + }; + /** The n_th element fitness in the population (see eoBestFitnessStat) */ @@ -242,6 +256,7 @@ public : virtual std::string className(void) const { return "eoNthElementFitnessStat"; } private : + /* Very old code... struct CmpFitness { CmpFitness(unsigned _whichElement, bool _maxim) : whichElement(_whichElement), maxim(_maxim) {} @@ -257,6 +272,7 @@ private : unsigned whichElement; bool maxim; }; + */ // for everything else template @@ -327,6 +343,7 @@ public: private : + /* Very old code... struct CmpFitness { CmpFitness(unsigned _which, bool _maxim) : which(_which), maxim(_maxim) {} @@ -342,6 +359,7 @@ private : unsigned which; bool maxim; }; + */ // default template @@ -354,6 +372,7 @@ private : /** @example t-eoSSGA.cpp */ + /** Keep the best individual found so far */ template @@ -366,7 +385,7 @@ public: : eoStat( EOT(), _description ) {} - void operator()(const eoPop& pop) + void operator()(const eoPop& pop) { EOT best = pop.best_element(); // on the first call, value() is invalid