Merge branch 'master' of ssh://eodev.git.sourceforge.net/gitroot/eodev/eodev

This commit is contained in:
Caner Candan 2010-11-17 11:54:07 +01:00
commit 8da8bfd20d
12 changed files with 180 additions and 30 deletions

View file

@ -29,6 +29,10 @@ Authors:
#include <functional> #include <functional>
#include <iostream> #include <iostream>
#include <utility> // for std::pair #include <utility> // for std::pair
#include <string>
#include <utils/eoStat.h>
#include <utils/eoLogger.h>
/** @addtogroup Evaluation /** @addtogroup Evaluation
* @{ * @{
@ -63,7 +67,7 @@ Authors:
template <class BaseType, class Compare > template <class BaseType, class Compare >
class eoDualFitness class eoDualFitness
{ {
private: protected:
//! Scalar type of the fitness (generally a double) //! Scalar type of the fitness (generally a double)
BaseType _value; BaseType _value;
@ -241,6 +245,68 @@ typedef eoDualFitness<double, std::greater<double> > eoMinimizingDualFitness;
template< class EOT> template< class EOT>
bool eoIsFeasible ( const EOT & sol ) { return sol.fitness().is_feasible(); } 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<class EOT, class T>
template<class EOT, class EOSTAT>
class eoDualStatSwitch : public eoStat< EOT, std::string >
{
public:
using eoStat<EOT,std::string>::value;
// eoDualStatSwitch( eoStat<EOT,T> & stat_feasible, eoStat<EOT,T> & 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<EOT,std::string>(
"?"+sep+"?",
stat_feasible.longName()+sep+stat_unfeasible.longName()
)
{ }
virtual void operator()( const eoPop<EOT> & pop )
{
eoPop<EOT> pop_feasible;
pop_feasible.reserve(pop.size());
eoPop<EOT> pop_unfeasible;
pop_unfeasible.reserve(pop.size());
for( typename eoPop<EOT>::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<EOT,T> & _stat_feasible;
// eoStat<EOT,T> & _stat_unfeasible;
EOSTAT & _stat_feasible;
EOSTAT & _stat_unfeasible;
std::string _sep;
};
/** @} */ /** @} */
#endif // _eoDualFitness_h_ #endif // _eoDualFitness_h_

View file

@ -29,7 +29,7 @@
#include <functional> #include <functional>
/** @ddtogroup Core /** @addtogroup Core
* @{ * @{
*/ */

View file

@ -71,7 +71,10 @@ public:
} }
/** Sets the number of generations to reach /** 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 ) { virtual void totalGenerations( unsigned long _tg ) {
repTotalGenerations = _tg; repTotalGenerations = _tg;
thisGeneration = 0; thisGeneration = 0;

View file

@ -37,9 +37,9 @@
/** /**
Replacement strategies that combine en eoMerge and an eoReduce. Replacement strategies that combine en eoMerge and an eoReduce.
@classes: eoMergeReduce, the base (pure abstract) class @class eoMergeReduce, the base (pure abstract) class
eoPlusReplacement the ES plus strategy @class eoPlusReplacement the ES plus strategy
eoCommaReplacement the ES comma strategy @class eoCommaReplacement the ES comma strategy
*/ */
/** /**

View file

@ -57,9 +57,9 @@ MS 12/12/2000
@see eoMerge, eoReduce, eoMergeReduce, eoReduceMerge @see eoMerge, eoReduce, eoMergeReduce, eoReduceMerge
@classes eoReplacement, base (pure abstract) class @class eoReplacement, base (pure abstract) class
eoGenerationalReplacement, as it says ... @class eoGenerationalReplacement, as it says ...
eoWeakElitistReplacement a wrapper to add elitism @class eoWeakElitistReplacement a wrapper to add elitism
*/ */

View file

@ -83,7 +83,10 @@ public:
} }
/** Sets the parameters (minimum nb of gen. + steady nb of gen.) /** 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 ) { virtual void totalGenerations( unsigned long _mg, unsigned long _sg ) {
repMinGenerations = _mg; repMinGenerations = _mg;
repSteadyGenerations = _sg; repSteadyGenerations = _sg;

View file

@ -42,8 +42,9 @@ kills the ones that are to die,
puts the ones that are to survive into the second argument puts the ones that are to survive into the second argument
removes them from the first pop argument removes them from the first pop argument
@classes: eoSurviveAndDie, eoDeterministicSurviveAndDie, @class eoSurviveAndDie
eoDeterministicSaDReplacement @class eoDeterministicSurviveAndDie,
@class eoDeterministicSaDReplacement
*/ */
/** @addtogroup Replacors /** @addtogroup Replacors

View file

@ -26,7 +26,12 @@ Authors:
*/ */
#ifdef _INTERIX
#include <io.h>
#else // _INTERIX
#include <unistd.h> #include <unistd.h>
#endif // ! _INTERIX
#include <fcntl.h> #include <fcntl.h>
#include <cstdlib> #include <cstdlib>
#include <cstdio> // used to define EOF #include <cstdio> // used to define EOF

View file

@ -38,7 +38,7 @@ Contact: http://eodev.sourceforge.net
#include <utils/eoParam.h> #include <utils/eoParam.h>
#include <eoPop.h> #include <eoPop.h>
#include <utils/eoMonitor.h> #include <utils/eoMonitor.h>
#include <utils/eoCheckPoint.h> //#include <utils/eoCheckPoint.h>
/** @defgroup Stats Statistics computation /** @defgroup Stats Statistics computation
* *
@ -435,21 +435,27 @@ public:
virtual void operator()( const eoPop<EOT> & _pop ) virtual void operator()( const eoPop<EOT> & _pop )
{ {
eoPop<EOT> pop = _pop; if( _pop.size() == 0 ) {
// how to implement value() = 0 ?
unsigned int quartile = pop.size()/4; } else {
std::nth_element( pop.begin(), pop.begin()+quartile*1, pop.end() ); eoPop<EOT> pop = _pop;
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; 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"; } virtual std::string className(void) const { return "eoInterquartileRangeStat"; }
}; };
/** @example t-eoIQRStat.cpp
*/
/** Compute the average size of indivudals over the population /** Compute the average size of indivudals over the population
* *

View file

@ -29,11 +29,10 @@
* eoRndGenerators, we might as well have these directly written without * eoRndGenerators, we might as well have these directly written without
* overhead * overhead
@classes: @class eoUniformInit uniform initialization for doubles, floats, ints, ...
eoUniformInit uniform initialization for doubles, floats, ints, ... @class eoBooleanInit biased init for booleans
eoBooleanInit biased init for booleans @class eoNormalInit normal intialization for doubles and floats
eoNormalInit normal intialization for doubles and floats @class eoNegExpInit negative exponential distributions "
eoNegExpInit negative exponential distributions "
*/ */
#ifndef eoUniformInit_h #ifndef eoUniformInit_h

View file

@ -25,8 +25,6 @@ LINK_DIRECTORIES(${EO_BINARY_DIR}/lib)
###################################################################################### ######################################################################################
SET (TEST_LIST SET (TEST_LIST
t-eoParetoFitness
t-eoPareto
t-eofitness t-eofitness
t-eoRandom t-eoRandom
t-eobin t-eobin
@ -65,8 +63,8 @@ SET (TEST_LIST
t-eoSyncEasyPSO t-eoSyncEasyPSO
t-eoOrderXover t-eoOrderXover
t-eoExtendedVelocity t-eoExtendedVelocity
# t-eoFrontSorter
t-eoLogger t-eoLogger
t-eoIQRStat
) )

69
eo/test/t-eoIQRStat.cpp Normal file
View file

@ -0,0 +1,69 @@
#include <eo>
#include <es.h>
#include <utils/eoStat.h>
#include "real_value.h"
typedef eoReal<eoMinimizingFitness> realVec;
double test( eoPop<realVec>& pop, double target_value )
{
eoEvalFuncPtr<realVec, double, const std::vector<double>&> eval( real_value );
eoPopLoopEval<realVec> pop_eval(eval);
pop_eval(pop,pop);
eoInterquartileRangeStat<realVec> 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<realVec> 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<double> normal(1,rng);
eoInitFixedLength<realVec> init_N(2, normal);
pop = eoPop<realVec>( 1000000, init_N );
double iqr = test(pop, 1.09);
if( iqr < 1.08 || iqr > 1.11 ) {
exit(1);
}
}