The perf2worth major check in

2 new important classes: eoPerf2Worth and eoSelectFromWorth
Instances of eoPerf2Worth are eoRanking and eoLinearFitScaling.
Coming soon (piece of cake now) are the niching strategies (sharing, clearing)
This commit is contained in:
evomarc 2001-02-16 08:21:25 +00:00
commit 7e849e2082
8 changed files with 465 additions and 121 deletions

View file

@ -18,8 +18,7 @@
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
Marc.Schoenauer@polytechnique.fr
Contact: Marc.Schoenauer@polytechnique.fr
mak@dhi.dk
*/
//-----------------------------------------------------------------------------
@ -29,61 +28,28 @@
//-----------------------------------------------------------------------------
#include <utils/eoRNG.h>
#include <utils/selectors.h>
#include <eoSelectOne.h>
#include <eoSelectFromWorth.h>
#include <eoRanking.h>
//-----------------------------------------------------------------------------
/** eoRankingSelect: select an individual proportional to its rank
this is actually the linearRanking
/** eoRankingSelect: select an individual by roulette wheel on its rank
* is an eoRouletteWorthSelect, i.e. a selector using a vector of worthes
* rather than the raw fitness (see eoSelectFromWorth.h)
* uses an internal eoRanking object which is an eoPerf2Worth<EOT, double>
*/
//-----------------------------------------------------------------------------
template <class EOT> class eoRankingSelect: public eoSelectOne<EOT>
template <class EOT>
class eoRankingSelect: public eoRouletteWorthSelect<EOT, double>
{
public:
/** Ctor:
* @param _p the selective pressure, should be in [1,2] (2 is the default)
* @param _pop an optional population
* @param _e exponent (1 == linear)
*/
eoRankingSelect(double _p = 2.0, const eoPop<EOT>& _pop = eoPop<EOT>()):
pressure(_p), rank(0), rankFitness(0)
{
if (_pop.size() > 0)
{
setup(_pop);
}
}
// COmputes the coefficients of the linear transform uin such a way that
// Pselect(Best) == Pselect(sizePop) == pressure/sizePop
// Pselect(average) == 1.0/sizePop
// Pselect(Worst == Pselect(1 == (2-pressure)/sizePop
void setup(const eoPop<EOT>& _pop)
{
_pop.sort(rank);
unsigned pSize =_pop.size();
rankFitness.resize(pSize);
double alpha = (2*pressure-2)/(pSize*(pSize-1));
double beta = (2-pressure)/pSize;
for (unsigned i=0; i<pSize; i++)
{
rankFitness[i] = alpha*(pSize-1-i)+beta;
}
}
/** do the selection, call roulette_wheel on rankFitness
*/
const EOT& operator()(const eoPop<EOT>& _pop)
{
unsigned selected = rng.roulette_wheel(rankFitness);
return *(rank[selected]);
}
eoRankingSelect(double _p = 2.0, double _e=1.0):
eoRouletteWorthSelect<EOT, double>(ranking), ranking(_p, _e) {}
private :
double pressure;
vector<const EOT *> rank;
vector<double> rankFitness;
eoRanking<EOT> ranking; // derived from eoPerf2Worth
};
#endif