From a22e642b091656cd0f0c3270c4a968f5461aa360 Mon Sep 17 00:00:00 2001 From: nojhan Date: Sun, 14 Nov 2010 15:07:50 +0100 Subject: [PATCH 1/7] a test binary for eoInterquartileRangeStat --- eo/test/CMakeLists.txt | 4 +-- eo/test/t-eoIQRStat.cpp | 69 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 eo/test/t-eoIQRStat.cpp diff --git a/eo/test/CMakeLists.txt b/eo/test/CMakeLists.txt index 2c0772def..4f194681e 100644 --- a/eo/test/CMakeLists.txt +++ b/eo/test/CMakeLists.txt @@ -25,8 +25,6 @@ LINK_DIRECTORIES(${EO_BINARY_DIR}/lib) ###################################################################################### SET (TEST_LIST - t-eoParetoFitness - t-eoPareto t-eofitness t-eoRandom t-eobin @@ -65,8 +63,8 @@ SET (TEST_LIST t-eoSyncEasyPSO t-eoOrderXover t-eoExtendedVelocity - # t-eoFrontSorter t-eoLogger + t-eoIQRStat ) diff --git a/eo/test/t-eoIQRStat.cpp b/eo/test/t-eoIQRStat.cpp new file mode 100644 index 000000000..60bcff8fe --- /dev/null +++ b/eo/test/t-eoIQRStat.cpp @@ -0,0 +1,69 @@ + +#include +#include +#include + +#include "real_value.h" + +typedef eoReal realVec; + +double test( eoPop& pop, double target_value ) +{ + eoEvalFuncPtr&> eval( real_value ); + + eoPopLoopEval pop_eval(eval); + + pop_eval(pop,pop); + + eoInterquartileRangeStat iqr_stat(0.0, "IQR"); + + iqr_stat( pop ); + + std::cout << iqr_stat.longName() << "=" << iqr_stat.value() << " should be " << target_value << std::endl; + + return iqr_stat.value(); +} + +int main() +{ + eoPop pop; + + // fixed test + realVec sol1(2,-1); + realVec sol2(2,-1); + realVec sol3(2,1); + realVec sol4(2,1); + pop.push_back( sol1 ); + pop.push_back( sol2 ); + pop.push_back( sol3 ); + pop.push_back( sol4 ); + // on the sphere function everyone has the same fitness of 1 + if( test(pop, 0) != 0 ) { + exit(1); + } + + pop.erase(pop.begin(),pop.end()); + + // fixed test + sol1 = realVec(2,0); + sol2 = realVec(2,0); + sol3 = realVec(2,1); + sol4 = realVec(2,1); + pop.push_back( sol1 ); + pop.push_back( sol2 ); + pop.push_back( sol3 ); + pop.push_back( sol4 ); + if( test(pop, 1) != 1 ) { + exit(1); + } + + // test on a random normal distribution + eoNormalGenerator normal(1,rng); + eoInitFixedLength init_N(2, normal); + pop = eoPop( 1000000, init_N ); + double iqr = test(pop, 1.09); + if( iqr < 1.08 || iqr > 1.11 ) { + exit(1); + } +} + From 4e36150ee8d4d176849d84efe65cc434880945b6 Mon Sep 17 00:00:00 2001 From: nojhan Date: Sun, 14 Nov 2010 15:11:46 +0100 Subject: [PATCH 2/7] eoInterquartileRangeStat example link to t-eoIQRStat --- eo/src/utils/eoStat.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eo/src/utils/eoStat.h b/eo/src/utils/eoStat.h index b4e8c4592..e308b8a9d 100644 --- a/eo/src/utils/eoStat.h +++ b/eo/src/utils/eoStat.h @@ -449,7 +449,8 @@ public: virtual std::string className(void) const { return "eoInterquartileRangeStat"; } }; - +/** @example t-eoIQRStat.cpp + */ /** Compute the average size of indivudals over the population * From 04f12b770e3c7889adebea3bef6dbba1b59fe3c1 Mon Sep 17 00:00:00 2001 From: nojhan Date: Sun, 14 Nov 2010 15:24:35 +0100 Subject: [PATCH 3/7] supress some doxygen warnings about \classes --- eo/src/eoFunctor.h | 2 +- eo/src/eoMergeReduce.h | 6 +++--- eo/src/eoReplacement.h | 6 +++--- eo/src/eoSurviveAndDie.h | 5 +++-- eo/src/utils/eoUniformInit.h | 9 ++++----- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/eo/src/eoFunctor.h b/eo/src/eoFunctor.h index 50c136642..e782328a3 100644 --- a/eo/src/eoFunctor.h +++ b/eo/src/eoFunctor.h @@ -29,7 +29,7 @@ #include -/** @ddtogroup Core +/** @addtogroup Core * @{ */ diff --git a/eo/src/eoMergeReduce.h b/eo/src/eoMergeReduce.h index b4c717528..8524f1d81 100644 --- a/eo/src/eoMergeReduce.h +++ b/eo/src/eoMergeReduce.h @@ -37,9 +37,9 @@ /** Replacement strategies that combine en eoMerge and an eoReduce. -@classes: eoMergeReduce, the base (pure abstract) class - eoPlusReplacement the ES plus strategy - eoCommaReplacement the ES comma strategy +@class eoMergeReduce, the base (pure abstract) class +@class eoPlusReplacement the ES plus strategy +@class eoCommaReplacement the ES comma strategy */ /** diff --git a/eo/src/eoReplacement.h b/eo/src/eoReplacement.h index 972aa61a4..2c2d89844 100644 --- a/eo/src/eoReplacement.h +++ b/eo/src/eoReplacement.h @@ -57,9 +57,9 @@ MS 12/12/2000 @see eoMerge, eoReduce, eoMergeReduce, eoReduceMerge -@classes eoReplacement, base (pure abstract) class - eoGenerationalReplacement, as it says ... - eoWeakElitistReplacement a wrapper to add elitism +@class eoReplacement, base (pure abstract) class +@class eoGenerationalReplacement, as it says ... +@class eoWeakElitistReplacement a wrapper to add elitism */ diff --git a/eo/src/eoSurviveAndDie.h b/eo/src/eoSurviveAndDie.h index 81e2e310c..3650a5365 100644 --- a/eo/src/eoSurviveAndDie.h +++ b/eo/src/eoSurviveAndDie.h @@ -42,8 +42,9 @@ kills the ones that are to die, puts the ones that are to survive into the second argument removes them from the first pop argument -@classes: eoSurviveAndDie, eoDeterministicSurviveAndDie, - eoDeterministicSaDReplacement +@class eoSurviveAndDie +@class eoDeterministicSurviveAndDie, +@class eoDeterministicSaDReplacement */ /** @addtogroup Replacors diff --git a/eo/src/utils/eoUniformInit.h b/eo/src/utils/eoUniformInit.h index 005b7f7ec..fa1b874dc 100644 --- a/eo/src/utils/eoUniformInit.h +++ b/eo/src/utils/eoUniformInit.h @@ -29,11 +29,10 @@ * eoRndGenerators, we might as well have these directly written without * overhead -@classes: - eoUniformInit uniform initialization for doubles, floats, ints, ... - eoBooleanInit biased init for booleans - eoNormalInit normal intialization for doubles and floats - eoNegExpInit negative exponential distributions " +@class eoUniformInit uniform initialization for doubles, floats, ints, ... +@class eoBooleanInit biased init for booleans +@class eoNormalInit normal intialization for doubles and floats +@class eoNegExpInit negative exponential distributions " */ #ifndef eoUniformInit_h From 327d9363af883d42885068a2420f166e65f1604d Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Mon, 15 Nov 2010 09:12:10 +0100 Subject: [PATCH 4/7] @todo: add an init method for continuators? --- eo/src/eoGenContinue.h | 5 ++++- eo/src/eoSteadyFitContinue.h | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/eo/src/eoGenContinue.h b/eo/src/eoGenContinue.h index 053824147..fac89d5dc 100644 --- a/eo/src/eoGenContinue.h +++ b/eo/src/eoGenContinue.h @@ -71,7 +71,10 @@ public: } /** Sets the number of generations to reach - and sets the current generation to 0 (the begin)*/ + and sets the current generation to 0 (the begin) + + @todo replace this by an "init" method + */ virtual void totalGenerations( unsigned long _tg ) { repTotalGenerations = _tg; thisGeneration = 0; diff --git a/eo/src/eoSteadyFitContinue.h b/eo/src/eoSteadyFitContinue.h index 2422ec1fc..7e5c8e21f 100644 --- a/eo/src/eoSteadyFitContinue.h +++ b/eo/src/eoSteadyFitContinue.h @@ -83,7 +83,10 @@ public: } /** Sets the parameters (minimum nb of gen. + steady nb of gen.) - and sets the current generation to 0 (the begin)*/ + and sets the current generation to 0 (the begin) + + @todo replace thi by an init method ? + */ virtual void totalGenerations( unsigned long _mg, unsigned long _sg ) { repMinGenerations = _mg; repSteadyGenerations = _sg; From fb8a8d79fddc5a1036f4cb851944b648c50003fa Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Mon, 15 Nov 2010 09:13:39 +0100 Subject: [PATCH 5/7] verify that pop is not empty before attempting to compute the IQR --- eo/src/utils/eoStat.h | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/eo/src/utils/eoStat.h b/eo/src/utils/eoStat.h index b4e8c4592..b7b912785 100644 --- a/eo/src/utils/eoStat.h +++ b/eo/src/utils/eoStat.h @@ -38,7 +38,7 @@ Contact: http://eodev.sourceforge.net #include #include #include -#include +//#include /** @defgroup Stats Statistics computation * @@ -435,16 +435,21 @@ public: virtual void operator()( const eoPop & _pop ) { - eoPop pop = _pop; + if( _pop.size() == 0 ) { + // how to implement value() = 0 ? - unsigned int quartile = pop.size()/4; - std::nth_element( pop.begin(), pop.begin()+quartile*1, pop.end() ); - typename EOT::Fitness Q1 = pop[quartile].fitness(); - - std::nth_element( pop.begin(), pop.begin()+quartile*3, pop.end() ); - typename EOT::Fitness Q3 = pop[quartile*3].fitness(); + } else { + eoPop pop = _pop; - value() = Q1 - Q3; + unsigned int quartile = pop.size()/4; + std::nth_element( pop.begin(), pop.begin()+quartile*1, pop.end() ); + typename EOT::Fitness Q1 = pop[quartile].fitness(); + + std::nth_element( pop.begin(), pop.begin()+quartile*3, pop.end() ); + typename EOT::Fitness Q3 = pop[quartile*3].fitness(); + + value() = Q1 - Q3; + } } virtual std::string className(void) const { return "eoInterquartileRangeStat"; } From 3d4d73a622f7a10b690bfc726daa2cd92fbc3249 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Mon, 15 Nov 2010 09:30:37 +0100 Subject: [PATCH 6/7] eoDualStatSwitch, a wrapper for computing stats on feasible and unfeasible individuals, separately --- eo/src/eoDualFitness.h | 68 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/eo/src/eoDualFitness.h b/eo/src/eoDualFitness.h index 3fb9c0a37..a758be051 100644 --- a/eo/src/eoDualFitness.h +++ b/eo/src/eoDualFitness.h @@ -29,6 +29,10 @@ Authors: #include #include #include // for std::pair +#include + +#include +#include /** @addtogroup Evaluation * @{ @@ -63,7 +67,7 @@ Authors: template class eoDualFitness { -private: +protected: //! Scalar type of the fitness (generally a double) BaseType _value; @@ -241,6 +245,68 @@ typedef eoDualFitness > eoMinimizingDualFitness; template< class EOT> bool eoIsFeasible ( const EOT & sol ) { return sol.fitness().is_feasible(); } + +/** Embed two eoStat and call the first one on the feasible individuals and + * the second one on the unfeasible ones, merge the two resulting value in + * a string, separated by a given marker. + */ +//template +template +class eoDualStatSwitch : public eoStat< EOT, std::string > +{ +public: + using eoStat::value; + +// eoDualStatSwitch( eoStat & stat_feasible, eoStat & stat_unfeasible, std::string sep=" " ) : + eoDualStatSwitch( EOSTAT & stat_feasible, EOSTAT & stat_unfeasible, std::string sep=" " ) : + _stat_feasible(stat_feasible), + _stat_unfeasible(stat_unfeasible), + _sep(sep), + eoStat( + "?"+sep+"?", + stat_feasible.longName()+sep+stat_unfeasible.longName() + ) + { } + + virtual void operator()( const eoPop & pop ) + { + eoPop pop_feasible; + pop_feasible.reserve(pop.size()); + + eoPop pop_unfeasible; + pop_unfeasible.reserve(pop.size()); + + for( typename eoPop::const_iterator ieot=pop.begin(), iend=pop.end(); ieot!=iend; ++ieot ) { + /* + if( ieot->invalid() ) { + eo::log << eo::errors << "ERROR: trying to access to an invalid fitness" << std::endl; + } + */ + if( ieot->fitness().is_feasible() ) { + pop_feasible.push_back( *ieot ); + } else { + pop_unfeasible.push_back( *ieot ); + } + } + + _stat_feasible( pop_feasible ); + _stat_unfeasible( pop_unfeasible ); + + std::ostringstream out; + out << _stat_feasible.value() << _sep << _stat_unfeasible.value(); + + value() = out.str(); + } + +protected: +// eoStat & _stat_feasible; +// eoStat & _stat_unfeasible; + EOSTAT & _stat_feasible; + EOSTAT & _stat_unfeasible; + + std::string _sep; +}; + /** @} */ #endif // _eoDualFitness_h_ From 8ecef39168b9e1979c1d8c58bd7b20b46e79c062 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Wed, 17 Nov 2010 11:41:43 +0100 Subject: [PATCH 7/7] fixed unistd.h portability issue --- eo/src/utils/eoLogger.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/eo/src/utils/eoLogger.cpp b/eo/src/utils/eoLogger.cpp index a0aa36e51..a729d0cf3 100644 --- a/eo/src/utils/eoLogger.cpp +++ b/eo/src/utils/eoLogger.cpp @@ -26,7 +26,12 @@ Authors: */ +#ifdef _INTERIX +#include +#else // _INTERIX #include +#endif // ! _INTERIX + #include #include #include // used to define EOF