REMOVE the generic fitness templates in eoSecondMomentStats in favor of scalar ones ; comment out old unused code
This commit is contained in:
parent
5453c8bda0
commit
188d1b4c56
1 changed files with 24 additions and 5 deletions
|
|
@ -32,6 +32,7 @@ Contact: http://eodev.sourceforge.net
|
||||||
#ifndef _eoStat_h
|
#ifndef _eoStat_h
|
||||||
#define _eoStat_h
|
#define _eoStat_h
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <numeric> // accumulate
|
#include <numeric> // accumulate
|
||||||
|
|
||||||
#include <eoFunctor.h>
|
#include <eoFunctor.h>
|
||||||
|
|
@ -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 EOT>
|
template <class EOT>
|
||||||
class eoSecondMomentStats : public eoStat<EOT, std::pair<typename EOT::Fitness, typename EOT::Fitness> >
|
// FIXME find a way to use generic Fitness types instead of scala fitness here :
|
||||||
|
// class eoSecondMomentStats : public eoStat<EOT, std::pair<typename EOT::Fitness, typename EOT::Fitness> >
|
||||||
|
// 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<ValueType>(),
|
||||||
|
// 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<EOT, std::pair<double,double> >
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
typedef typename EOT::Fitness FitT;
|
// typedef typename EOT::Fitness FitT;
|
||||||
|
typedef double FitT;
|
||||||
|
|
||||||
using eoStat<EOT, std::pair<FitT, FitT> >::value;
|
using eoStat<EOT, std::pair<FitT, FitT> >::value;
|
||||||
typedef std::pair<FitT, FitT> SquarePair;
|
typedef std::pair<FitT, FitT> SquarePair;
|
||||||
|
|
@ -209,9 +221,11 @@ public :
|
||||||
value().second = sqrt( (result.second - n * value().first * value().first) / (n - 1.0)); // stdev
|
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)
|
The n_th element fitness in the population (see eoBestFitnessStat)
|
||||||
*/
|
*/
|
||||||
|
|
@ -242,6 +256,7 @@ public :
|
||||||
virtual std::string className(void) const { return "eoNthElementFitnessStat"; }
|
virtual std::string className(void) const { return "eoNthElementFitnessStat"; }
|
||||||
private :
|
private :
|
||||||
|
|
||||||
|
/* Very old code...
|
||||||
struct CmpFitness
|
struct CmpFitness
|
||||||
{
|
{
|
||||||
CmpFitness(unsigned _whichElement, bool _maxim) : whichElement(_whichElement), maxim(_maxim) {}
|
CmpFitness(unsigned _whichElement, bool _maxim) : whichElement(_whichElement), maxim(_maxim) {}
|
||||||
|
|
@ -257,6 +272,7 @@ private :
|
||||||
unsigned whichElement;
|
unsigned whichElement;
|
||||||
bool maxim;
|
bool maxim;
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
// for everything else
|
// for everything else
|
||||||
template <class T>
|
template <class T>
|
||||||
|
|
@ -327,6 +343,7 @@ public:
|
||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
||||||
|
/* Very old code...
|
||||||
struct CmpFitness
|
struct CmpFitness
|
||||||
{
|
{
|
||||||
CmpFitness(unsigned _which, bool _maxim) : which(_which), maxim(_maxim) {}
|
CmpFitness(unsigned _which, bool _maxim) : which(_which), maxim(_maxim) {}
|
||||||
|
|
@ -342,6 +359,7 @@ private :
|
||||||
unsigned which;
|
unsigned which;
|
||||||
bool maxim;
|
bool maxim;
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
// default
|
// default
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|
@ -354,6 +372,7 @@ private :
|
||||||
/** @example t-eoSSGA.cpp
|
/** @example t-eoSSGA.cpp
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/** Keep the best individual found so far
|
/** Keep the best individual found so far
|
||||||
*/
|
*/
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
|
|
@ -366,7 +385,7 @@ public:
|
||||||
: eoStat<EOT, EOT>( EOT(), _description )
|
: eoStat<EOT, EOT>( EOT(), _description )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void operator()(const eoPop<EOT>& pop)
|
void operator()(const eoPop<EOT>& pop)
|
||||||
{
|
{
|
||||||
EOT best = pop.best_element();
|
EOT best = pop.best_element();
|
||||||
// on the first call, value() is invalid
|
// on the first call, value() is invalid
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue