Adding sharing - needed to modify quite a few files, like eoDistance.h
make_algo_scalar.h and all related files, and the like
This commit is contained in:
parent
13c7062858
commit
795f63b7fe
14 changed files with 244 additions and 93 deletions
|
|
@ -39,6 +39,7 @@
|
|||
#include <eoFitnessScalingSelect.h>
|
||||
#include <eoRankingSelect.h>
|
||||
#include <eoStochTournamentSelect.h>
|
||||
#include <eoSharingSelect.h>
|
||||
|
||||
// Breeders
|
||||
#include <eoGeneralBreeder.h>
|
||||
|
|
@ -49,6 +50,9 @@
|
|||
#include <eoReduceMerge.h>
|
||||
#include <eoSurviveAndDie.h>
|
||||
|
||||
// distance
|
||||
#include <utils/eoDistance.h>
|
||||
|
||||
// Algorithm (only this one needed)
|
||||
#include <eoEasyEA.h>
|
||||
|
||||
|
|
@ -70,11 +74,18 @@
|
|||
* is actually templatized here
|
||||
*/
|
||||
|
||||
|
||||
template <class EOT>
|
||||
eoAlgo<EOT> & do_make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<EOT>& _eval, eoContinue<EOT>& _continue, eoGenOp<EOT>& _op)
|
||||
eoAlgo<EOT> & do_make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<EOT>& _eval, eoContinue<EOT>& _continue, eoGenOp<EOT>& _op, eoDistance<EOT> * _dist = NULL)
|
||||
{
|
||||
// the selection
|
||||
eoValueParam<eoParamParamType>& selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection", "Selection: Roulette, Ranking(p,e), DetTour(T), StochTour(t) or Sequential(ordered/unordered)", 'S', "Evolution Engine");
|
||||
// the selection : help and comment depend on whether or not a distance is passed
|
||||
std::string comment;
|
||||
if (_dist == NULL)
|
||||
comment = "Selection: DetTour(T), StochTour(t), Roulette, Ranking(p,e) or Sequential(ordered/unordered)";
|
||||
else
|
||||
comment = "Selection: DetTour(T), StochTour(t), Roulette, Ranking(p,e), Sharing(sigma_share) or Sequential(ordered/unordered)";
|
||||
|
||||
eoValueParam<eoParamParamType>& selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection", comment, 'S', "Evolution Engine");
|
||||
|
||||
eoParamParamType & ppSelect = selectionParam.value(); // std::pair<std::string,std::vector<std::string> >
|
||||
|
||||
|
|
@ -94,6 +105,23 @@ eoAlgo<EOT> & do_make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc
|
|||
detSize = atoi(ppSelect.second[0].c_str());
|
||||
select = new eoDetTournamentSelect<EOT>(detSize);
|
||||
}
|
||||
else if (ppSelect.first == std::string("Sharing"))
|
||||
{
|
||||
double nicheSize;
|
||||
|
||||
if (!ppSelect.second.size()) // no parameter added
|
||||
{
|
||||
std::cerr << "WARNING, no parameter passed to Sharing, using 0.5" << std::endl;
|
||||
nicheSize = 0.5;
|
||||
// put back 2 in parameter for consistency (and status file)
|
||||
ppSelect.second.push_back(std::string("0.5"));
|
||||
}
|
||||
else // parameter passed by user as DetTour(T)
|
||||
nicheSize = atof(ppSelect.second[0].c_str());
|
||||
if (_dist == NULL) // no distance
|
||||
throw std::runtime_error("You didn't specify a distance when calling make_algo_scalar and using sharing");
|
||||
select = new eoSharingSelect<EOT>(nicheSize, *_dist);
|
||||
}
|
||||
else if (ppSelect.first == std::string("StochTour"))
|
||||
{
|
||||
double p;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
#ifndef _eoSelectFromWorth_h
|
||||
#define _eoSelectFromWorth_h
|
||||
|
||||
|
||||
#include <iostream.h>
|
||||
//-----------------------------------------------------------------------------
|
||||
#include <eoSelectOne.h>
|
||||
#include <eoPerf2Worth.h>
|
||||
|
|
@ -197,6 +197,12 @@ public:
|
|||
*/
|
||||
virtual const EOT& operator()(const eoPop<EOT>& _pop)
|
||||
{
|
||||
// cout << "On affiche les worths\n";
|
||||
// for (unsigned i=0;
|
||||
// i<perf2Worth.value().size();
|
||||
// i++)
|
||||
// cout << perf2Worth.value().operator[](i) << "\n";
|
||||
// cout << endl;
|
||||
worthIterator it = roulette_wheel(
|
||||
perf2Worth.value().begin(),
|
||||
perf2Worth.value().end(),
|
||||
|
|
|
|||
|
|
@ -32,65 +32,14 @@
|
|||
/** Sharing is a perf2worth class that implements
|
||||
* Goldberg and Richardson's basic sharing
|
||||
*/
|
||||
// template <class EOT, class Dist = eoQuadDistance<EOT> >
|
||||
template <class EOT>
|
||||
class eoSharing : public eoPerf2Worth<EOT, double>
|
||||
{
|
||||
public:
|
||||
/** Ctor with only nicheSize: will use the default eoQuadDistance */
|
||||
eoSharing(double _nicheSize) : eoPerf2Worth("Sharing"),
|
||||
nicheSize(_nicheSize),
|
||||
dist(repDist)
|
||||
{}
|
||||
|
||||
eoSharing(double _nicheSize, Dist _dist) : eoPerf2Worth("Sharing"),
|
||||
nicheSize(_nicheSize),
|
||||
dist(_dist)
|
||||
{}
|
||||
|
||||
/** Computes shared fitnesses
|
||||
*/
|
||||
void operator()(const eoPop<EOT>& _pop)
|
||||
{
|
||||
unsigned i, j,
|
||||
pSize=_pop.size();
|
||||
if (pSize <= 1)
|
||||
throw std::runtime_error("Apptempt to do sharing with population of size 1");
|
||||
value.resize(pSize);
|
||||
std::vector<double> sim(pSize); // to hold the similarities
|
||||
std::vector<double> distMatrix(pSize*(pSize-1)/2); // to hold the distances
|
||||
|
||||
// compute the distances
|
||||
distMatrix(0,0)=0;
|
||||
for (i=1; i<pSize; i++)
|
||||
{
|
||||
distMatrix(i,i)=0;
|
||||
for (j=0; j<i; j++)
|
||||
{
|
||||
distMatrix(i,j) = distMatrix(j,i) = dist(_pop[i], _pop[j]);
|
||||
}
|
||||
}
|
||||
|
||||
// compute the similarities
|
||||
for (i=0; i<pSize; i++)
|
||||
{
|
||||
double sum=0.0;
|
||||
for (j=0; j<pSize; j++)
|
||||
sum += distMatrix(i,j);
|
||||
sim[i] = sum;
|
||||
|
||||
}
|
||||
// now set the worthes values
|
||||
for (i = 0; i < _pop.size(); ++i)
|
||||
value()[i]=_pop[i].fitness()/sim[i];
|
||||
}
|
||||
|
||||
// First a helper class
|
||||
// helper class to hold distances
|
||||
class dMatrix : public std::vector<double>
|
||||
{
|
||||
public:
|
||||
// Ctor : sets size
|
||||
dMatrix(unsigned _s) : std::vector<double>(_s*(_s-1)), rSize(_s) {}
|
||||
dMatrix(unsigned _s) : std::vector<double>(_s*_s), rSize(_s) {}
|
||||
|
||||
/** simple accessor */
|
||||
double operator()(unsigned _i, unsigned _j) const
|
||||
|
|
@ -121,11 +70,76 @@ class eoSharing : public eoPerf2Worth<EOT, double>
|
|||
unsigned rSize; // row size (== number of columns!)
|
||||
};
|
||||
|
||||
|
||||
// template <class EOT, class Dist = eoQuadDistance<EOT> >
|
||||
template <class EOT>
|
||||
class eoSharing : public eoPerf2Worth<EOT>
|
||||
{
|
||||
public:
|
||||
/* Ctor requires a distance - cannot have a default distance! */
|
||||
eoSharing(double _nicheSize, eoDistance<EOT> & _dist) : eoPerf2Worth<EOT>("Sharing"),
|
||||
nicheSize(_nicheSize),
|
||||
dist(_dist)
|
||||
{}
|
||||
|
||||
/** Computes shared fitnesses
|
||||
*/
|
||||
void operator()(const eoPop<EOT>& _pop)
|
||||
{
|
||||
unsigned i, j,
|
||||
pSize=_pop.size();
|
||||
if (pSize <= 1)
|
||||
throw std::runtime_error("Apptempt to do sharing with population of size 1");
|
||||
value().resize(pSize);
|
||||
std::vector<double> sim(pSize); // to hold the similarities
|
||||
dMatrix distMatrix(pSize*(pSize-1)/2); // to hold the distances
|
||||
|
||||
// compute the similarities (wrong name for distMatrix, I know)
|
||||
distMatrix(0,0)=1;
|
||||
for (i=1; i<pSize; i++)
|
||||
{
|
||||
distMatrix(i,i)=1;
|
||||
for (j=0; j<i; j++)
|
||||
{
|
||||
double d = dist(_pop[i], _pop[j]);
|
||||
distMatrix(i,j) =
|
||||
distMatrix(j,i) = ( d>nicheSize ? 0 : 1-(d/nicheSize) );
|
||||
}
|
||||
}
|
||||
|
||||
// cout << "Matrice des similarités\n";
|
||||
// for (i=0; i<pSize; i++)
|
||||
// {
|
||||
// for (j=0; j<pSize; j++)
|
||||
// {
|
||||
// cout << distMatrix(i,j) << " ";
|
||||
// }
|
||||
// cout << "\n";
|
||||
// }
|
||||
// cout << endl;
|
||||
|
||||
// cout << "Les similarités cumulées\n";
|
||||
// compute the cumulated similarities
|
||||
for (i=0; i<pSize; i++)
|
||||
{
|
||||
double sum=0.0;
|
||||
for (j=0; j<pSize; j++)
|
||||
sum += distMatrix(i,j);
|
||||
sim[i] = sum;
|
||||
// cout << sim[i] << " ";
|
||||
}
|
||||
// cout << endl;
|
||||
|
||||
// now set the worthes values
|
||||
for (i = 0; i < _pop.size(); ++i)
|
||||
value()[i]=_pop[i].fitness()/sim[i];
|
||||
}
|
||||
// private data of class eoSharing
|
||||
private:
|
||||
double nicheSize;
|
||||
eoQuadDistance<EOT> repDist; // default distance
|
||||
eoDistance & dist; // allows to pass a specific distance
|
||||
eoDistance<EOT> & dist; // specific distance
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
54
eo/src/eoSharingSelect.h
Normal file
54
eo/src/eoSharingSelect.h
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoSharingSelect.h
|
||||
// (c) GeNeura Team, 1998, Maarten Keijzer 2000, Marc Schoenauer 2001
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
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: Marc.Schoenauer@polytechnique.fr
|
||||
mak@dhi.dk
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef eoSharingSelect_h
|
||||
#define eoSharingSelect_h
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <eoSelectFromWorth.h>
|
||||
#include <eoSharing.h>
|
||||
|
||||
/** eoRankingSelect: select an individual by roulette wheel on its rank
|
||||
* is an eoRouletteWorthSelect, i.e. a selector using a std::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 eoSharingSelect: public eoRouletteWorthSelect<EOT, double>
|
||||
{
|
||||
public:
|
||||
/** Ctor:
|
||||
* @param _s the sigma_share
|
||||
*/
|
||||
eoSharingSelect(double _sigma, eoDistance<EOT> & _dist):
|
||||
eoRouletteWorthSelect<EOT, double>(sharing), sharing(_sigma, _dist) {}
|
||||
|
||||
private :
|
||||
eoSharing<EOT> sharing; // derived from eoPerf2Worth
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -51,34 +51,34 @@
|
|||
|
||||
// Algo
|
||||
///////
|
||||
eoAlgo<eoEsSimple<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsSimple<double> >& _eval, eoContinue<eoEsSimple<double> >& _continue, eoGenOp<eoEsSimple<double> >& _op)
|
||||
eoAlgo<eoEsSimple<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsSimple<double> >& _eval, eoContinue<eoEsSimple<double> >& _continue, eoGenOp<eoEsSimple<double> >& _op, eoDistance<eoEsSimple<double> >* _dist)
|
||||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||
}
|
||||
|
||||
eoAlgo<eoEsSimple<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsSimple<eoMinimizingFitness> >& _eval, eoContinue<eoEsSimple<eoMinimizingFitness> >& _continue, eoGenOp<eoEsSimple<eoMinimizingFitness> >& _op)
|
||||
eoAlgo<eoEsSimple<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsSimple<eoMinimizingFitness> >& _eval, eoContinue<eoEsSimple<eoMinimizingFitness> >& _continue, eoGenOp<eoEsSimple<eoMinimizingFitness> >& _op, eoDistance<eoEsSimple<eoMinimizingFitness> >* _dist)
|
||||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||
}
|
||||
|
||||
//////////////
|
||||
eoAlgo<eoEsStdev<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsStdev<double> >& _eval, eoContinue<eoEsStdev<double> >& _continue, eoGenOp<eoEsStdev<double> >& _op)
|
||||
eoAlgo<eoEsStdev<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsStdev<double> >& _eval, eoContinue<eoEsStdev<double> >& _continue, eoGenOp<eoEsStdev<double> >& _op, eoDistance<eoEsStdev<double> >* _dist)
|
||||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||
}
|
||||
|
||||
eoAlgo<eoEsStdev<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsStdev<eoMinimizingFitness> >& _eval, eoContinue<eoEsStdev<eoMinimizingFitness> >& _continue, eoGenOp<eoEsStdev<eoMinimizingFitness> >& _op)
|
||||
eoAlgo<eoEsStdev<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsStdev<eoMinimizingFitness> >& _eval, eoContinue<eoEsStdev<eoMinimizingFitness> >& _continue, eoGenOp<eoEsStdev<eoMinimizingFitness> >& _op, eoDistance<eoEsStdev<eoMinimizingFitness> >* _dist)
|
||||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||
}
|
||||
|
||||
///////////////
|
||||
eoAlgo<eoEsFull<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsFull<double> >& _eval, eoContinue<eoEsFull<double> >& _continue, eoGenOp<eoEsFull<double> >& _op)
|
||||
eoAlgo<eoEsFull<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsFull<double> >& _eval, eoContinue<eoEsFull<double> >& _continue, eoGenOp<eoEsFull<double> >& _op, eoDistance<eoEsFull<double> >* _dist)
|
||||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||
}
|
||||
|
||||
eoAlgo<eoEsFull<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsFull<eoMinimizingFitness> >& _eval, eoContinue<eoEsFull<eoMinimizingFitness> >& _continue, eoGenOp<eoEsFull<eoMinimizingFitness> >& _op)
|
||||
eoAlgo<eoEsFull<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsFull<eoMinimizingFitness> >& _eval, eoContinue<eoEsFull<eoMinimizingFitness> >& _continue, eoGenOp<eoEsFull<eoMinimizingFitness> >& _op, eoDistance<eoEsFull<eoMinimizingFitness> >* _dist)
|
||||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,13 +49,13 @@
|
|||
|
||||
// Algo
|
||||
///////
|
||||
eoAlgo<eoReal<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoReal<double> >& _eval, eoContinue<eoReal<double> >& _continue, eoGenOp<eoReal<double> >& _op)
|
||||
eoAlgo<eoReal<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoReal<double> >& _eval, eoContinue<eoReal<double> >& _continue, eoGenOp<eoReal<double> >& _op, eoDistance<eoReal<double> >* _dist)
|
||||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op, _dist);
|
||||
}
|
||||
|
||||
eoAlgo<eoReal<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoReal<eoMinimizingFitness> >& _eval, eoContinue<eoReal<eoMinimizingFitness> >& _continue, eoGenOp<eoReal<eoMinimizingFitness> >& _op)
|
||||
eoAlgo<eoReal<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoReal<eoMinimizingFitness> >& _eval, eoContinue<eoReal<eoMinimizingFitness> >& _continue, eoGenOp<eoReal<eoMinimizingFitness> >& _op, eoDistance<eoReal<eoMinimizingFitness> >* _dist)
|
||||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op, _dist);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@
|
|||
#include <utils/eoCheckPoint.h>
|
||||
#include <eoGenOp.h>
|
||||
#include <eoPop.h>
|
||||
#include <utils/eoDistance.h>
|
||||
|
||||
#include <es/eoEsSimple.h> // one Sigma per individual
|
||||
#include <es/eoEsStdev.h> // one sigmal per object variable
|
||||
|
|
@ -119,14 +120,14 @@ eoCheckPoint<eoEsFull<eoMinimizingFitness> >& make_checkpoint(eoParser& _parser,
|
|||
|
||||
|
||||
// the algo
|
||||
eoAlgo<eoEsSimple<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsSimple<double> >& _eval, eoContinue<eoEsSimple<double> >& _ccontinue, eoGenOp<eoEsSimple<double> >& _op);
|
||||
eoAlgo<eoEsSimple<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsSimple<eoMinimizingFitness> >& _eval, eoContinue<eoEsSimple<eoMinimizingFitness> >& _ccontinue, eoGenOp<eoEsSimple<eoMinimizingFitness> >& _op);
|
||||
eoAlgo<eoEsSimple<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsSimple<double> >& _eval, eoContinue<eoEsSimple<double> >& _ccontinue, eoGenOp<eoEsSimple<double> >& _op, eoDistance<eoEsSimple<double> >* _dist = NULL);
|
||||
eoAlgo<eoEsSimple<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsSimple<eoMinimizingFitness> >& _eval, eoContinue<eoEsSimple<eoMinimizingFitness> >& _ccontinue, eoGenOp<eoEsSimple<eoMinimizingFitness> >& _op, eoDistance<eoEsSimple<eoMinimizingFitness> >* _dist = NULL);
|
||||
|
||||
eoAlgo<eoEsStdev<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsStdev<double> >& _eval, eoContinue<eoEsStdev<double> >& _ccontinue, eoGenOp<eoEsStdev<double> >& _op);
|
||||
eoAlgo<eoEsStdev<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsStdev<eoMinimizingFitness> >& _eval, eoContinue<eoEsStdev<eoMinimizingFitness> >& _ccontinue, eoGenOp<eoEsStdev<eoMinimizingFitness> >& _op);
|
||||
eoAlgo<eoEsStdev<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsStdev<double> >& _eval, eoContinue<eoEsStdev<double> >& _ccontinue, eoGenOp<eoEsStdev<double> >& _op, eoDistance<eoEsStdev<double> >* _dist = NULL);
|
||||
eoAlgo<eoEsStdev<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsStdev<eoMinimizingFitness> >& _eval, eoContinue<eoEsStdev<eoMinimizingFitness> >& _ccontinue, eoGenOp<eoEsStdev<eoMinimizingFitness> >& _op, eoDistance<eoEsStdev<eoMinimizingFitness> >* _dist = NULL);
|
||||
|
||||
eoAlgo<eoEsFull<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsFull<double> >& _eval, eoContinue<eoEsFull<double> >& _ccontinue, eoGenOp<eoEsFull<double> >& _op);
|
||||
eoAlgo<eoEsFull<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsFull<eoMinimizingFitness> >& _eval, eoContinue<eoEsFull<eoMinimizingFitness> >& _ccontinue, eoGenOp<eoEsFull<eoMinimizingFitness> >& _op);
|
||||
eoAlgo<eoEsFull<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsFull<double> >& _eval, eoContinue<eoEsFull<double> >& _ccontinue, eoGenOp<eoEsFull<double> >& _op, eoDistance<eoEsFull<double> >* _dist = NULL);
|
||||
eoAlgo<eoEsFull<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoEsFull<eoMinimizingFitness> >& _eval, eoContinue<eoEsFull<eoMinimizingFitness> >& _ccontinue, eoGenOp<eoEsFull<eoMinimizingFitness> >& _op, eoDistance<eoEsFull<eoMinimizingFitness> >* _dist = NULL);
|
||||
|
||||
// run
|
||||
void run_ea(eoAlgo<eoEsSimple<double> >& _ga, eoPop<eoEsSimple<double> >& _pop);
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@
|
|||
#include <utils/eoCheckPoint.h>
|
||||
#include <eoGenOp.h>
|
||||
#include <eoPop.h>
|
||||
#include <utils/eoDistance.h>
|
||||
|
||||
#include <es/eoRealInitBounded.h>
|
||||
#include <es/eoReal.h>
|
||||
|
|
@ -85,9 +86,9 @@ eoCheckPoint<eoReal<eoMinimizingFitness> >& make_checkpoint(eoParser& _parser, e
|
|||
|
||||
|
||||
// the algo
|
||||
eoAlgo<eoReal<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoReal<double> >& _eval, eoContinue<eoReal<double> >& _ccontinue, eoGenOp<eoReal<double> >& _op);
|
||||
eoAlgo<eoReal<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoReal<double> >& _eval, eoContinue<eoReal<double> >& _ccontinue, eoGenOp<eoReal<double> >& _op, eoDistance<eoReal<double> >* _dist = NULL);
|
||||
|
||||
eoAlgo<eoReal<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoReal<eoMinimizingFitness> >& _eval, eoContinue<eoReal<eoMinimizingFitness> >& _ccontinue, eoGenOp<eoReal<eoMinimizingFitness> >& _op);
|
||||
eoAlgo<eoReal<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoReal<eoMinimizingFitness> >& _eval, eoContinue<eoReal<eoMinimizingFitness> >& _ccontinue, eoGenOp<eoReal<eoMinimizingFitness> >& _op, eoDistance<eoReal<eoMinimizingFitness> >* _dist = NULL);
|
||||
|
||||
// run
|
||||
void run_ea(eoAlgo<eoReal<double> >& _ga, eoPop<eoReal<double> >& _pop);
|
||||
|
|
|
|||
|
|
@ -52,13 +52,13 @@
|
|||
|
||||
// Algo
|
||||
///////
|
||||
eoAlgo<eoBit<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoBit<double> >& _eval, eoContinue<eoBit<double> >& _continue, eoGenOp<eoBit<double> >& _op)
|
||||
eoAlgo<eoBit<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoBit<double> >& _eval, eoContinue<eoBit<double> >& _continue, eoGenOp<eoBit<double> >& _op, eoDistance<eoBit<double> >* _dist)
|
||||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op, _dist);
|
||||
}
|
||||
|
||||
eoAlgo<eoBit<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoBit<eoMinimizingFitness> >& _eval, eoContinue<eoBit<eoMinimizingFitness> >& _continue, eoGenOp<eoBit<eoMinimizingFitness> >& _op)
|
||||
eoAlgo<eoBit<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoBit<eoMinimizingFitness> >& _eval, eoContinue<eoBit<eoMinimizingFitness> >& _continue, eoGenOp<eoBit<eoMinimizingFitness> >& _op, eoDistance<eoBit<eoMinimizingFitness> >* _dist)
|
||||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op, _dist);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@
|
|||
#include <utils/eoCheckPoint.h>
|
||||
#include <eoGenOp.h>
|
||||
#include <eoPop.h>
|
||||
#include <utils/eoDistance.h>
|
||||
|
||||
#include <ga/eoBit.h>
|
||||
|
||||
|
|
@ -77,9 +78,9 @@ eoCheckPoint<eoBit<eoMinimizingFitness> >& make_checkpoint(eoParser& _parser, eo
|
|||
|
||||
|
||||
// the algo
|
||||
eoAlgo<eoBit<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoBit<double> >& _eval, eoContinue<eoBit<double> >& _ccontinue, eoGenOp<eoBit<double> >& _op);
|
||||
eoAlgo<eoBit<double> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoBit<double> >& _eval, eoContinue<eoBit<double> >& _ccontinue, eoGenOp<eoBit<double> >& _op, eoDistance<eoBit<double> >* _dist = NULL);
|
||||
|
||||
eoAlgo<eoBit<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoBit<eoMinimizingFitness> >& _eval, eoContinue<eoBit<eoMinimizingFitness> >& _ccontinue, eoGenOp<eoBit<eoMinimizingFitness> >& _op);
|
||||
eoAlgo<eoBit<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<eoBit<eoMinimizingFitness> >& _eval, eoContinue<eoBit<eoMinimizingFitness> >& _ccontinue, eoGenOp<eoBit<eoMinimizingFitness> >& _op, eoDistance<eoBit<eoMinimizingFitness> >* _dist = NULL);
|
||||
|
||||
// run
|
||||
void run_ea(eoAlgo<eoBit<double> >& _ga, eoPop<eoBit<double> >& _pop);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@
|
|||
#define _eoDistance_H
|
||||
|
||||
#include <eoFunctor.h>
|
||||
|
||||
/**
|
||||
This is a generic class for distance functors:
|
||||
takes 2 things ane returns a double
|
||||
|
|
@ -36,27 +35,63 @@ template< class EOT >
|
|||
class eoDistance : public eoBF<const EOT &, const EOT &, double>
|
||||
{};
|
||||
|
||||
|
||||
/**
|
||||
This is a generic class for Euclidain distance computation:
|
||||
This is a generic class for Euclidain distance (L2 norm) computation:
|
||||
assumes the 2 things are std::vectors of something that is double-castable
|
||||
*/
|
||||
|
||||
template< class EOT >
|
||||
class eoQuadDistance : public eoDistance<EOT>
|
||||
{
|
||||
public:
|
||||
double operator()(const EOT & _v1, const EOT & _v2)
|
||||
{
|
||||
double sum=0.0;
|
||||
double sum=0.0;
|
||||
for (unsigned i=0; i<_v1.size(); i++)
|
||||
{
|
||||
double r = static_cast<double> (_v1[i]) - static_cast<double> (_v2[i]);
|
||||
sum += r*r;
|
||||
}
|
||||
return sqrt(sum);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
This is a generic class for L1 distance computation:
|
||||
assumes the 2 things are std::vectors of something
|
||||
that is double-castable
|
||||
For bitstrings, this is the Hamming distance
|
||||
*/
|
||||
template< class EOT >
|
||||
class eoHammingDistance : public eoDistance<EOT>
|
||||
{
|
||||
public:
|
||||
double operator()(const EOT & _v1, const EOT & _v2)
|
||||
{
|
||||
double sum=0.0;
|
||||
for (unsigned i=0; i<_v1.size(); i++)
|
||||
{
|
||||
double r = static_cast<double> (_v1[i]) - static_cast<double> (_v2[i]);
|
||||
sum += fabs(r);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
};
|
||||
|
||||
/* this distance measures the difference in fitness
|
||||
* I am not sure it can be of any use, though ...
|
||||
* except for some testing
|
||||
*/
|
||||
template< class EOT >
|
||||
class eoFitnessDistance : public eoDistance<EOT>
|
||||
{
|
||||
public:
|
||||
double operator()(const EOT & _v1, const EOT & _v2)
|
||||
{
|
||||
double d = _v1.fitness() - _v2.fitness();
|
||||
return sqrt(d*d);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ CXXFLAGS = -g -Wall
|
|||
|
||||
# PLEASE don't break the line (see create_batch.sh)
|
||||
|
||||
check_PROGRAMS = t-eoParetoFitness t-eoPareto t-eofitness t-eoRandom t-eobin t-eoVirus t-MGE t-MGE1bit t-MGE-control t-eoStateAndParser t-eoCheckpointing t-eoSSGA t-eoExternalEO t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA t-eoReal t-eoVector t-eoESAll t-eoPBIL t-eoFitnessAssembled t-eoFitnessAssembledEA t-eoRoulette
|
||||
check_PROGRAMS = t-eoParetoFitness t-eoPareto t-eofitness t-eoRandom t-eobin t-eoVirus t-MGE t-MGE1bit t-MGE-control t-eoStateAndParser t-eoCheckpointing t-eoSSGA t-eoExternalEO t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA t-eoReal t-eoVector t-eoESAll t-eoPBIL t-eoFitnessAssembled t-eoFitnessAssembledEA t-eoRoulette t-eoSharing
|
||||
|
||||
#The run_tests script can be used to check various arguments
|
||||
TESTS=$(check_PROGRAMS) run_tests
|
||||
|
|
@ -198,3 +198,10 @@ t_eoRoulette_LDFLAGS = -lm
|
|||
t_eoRoulette_LDADD = $(LDADDS)
|
||||
|
||||
###############################################################################
|
||||
|
||||
t_eoSharing_SOURCES = t-eoSharing.cpp
|
||||
t_eoSharing_DEPENDENCIES = $(DEPS)
|
||||
t_eoSharing_LDFLAGS = -lm
|
||||
t_eoSharing_LDADD = $(LDADDS)
|
||||
|
||||
###############################################################################
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -30,13 +30,17 @@ int main(int argc, char* argv[])
|
|||
|
||||
// EVAL
|
||||
// The evaluation fn - encapsulated into an eval counter for output
|
||||
eoEvalFuncPtr<EOT, float> mainEval( binary_value<EOT> );
|
||||
eoEvalFuncPtr<EOT, double> mainEval( binary_value<EOT> );
|
||||
eoEvalFuncCounter<EOT> eval(mainEval);
|
||||
|
||||
// REPRESENTATION
|
||||
// the genotype - through a genotype initializer
|
||||
eoInit<EOT>& init = make_genotype(parser, state, EOT());
|
||||
|
||||
// if you want to do sharing, you'll need a distance.
|
||||
// here Hamming distance
|
||||
eoHammingDistance<EOT> dist;
|
||||
|
||||
// OPERATORS
|
||||
// Build the variation operator (any seq/prop construct)
|
||||
eoGenOp<EOT>& op = make_op(parser, state, init);
|
||||
|
|
@ -56,7 +60,7 @@ int main(int argc, char* argv[])
|
|||
eoCheckPoint<EOT> & checkpoint = make_checkpoint(parser, state, eval, term);
|
||||
// GENERATION
|
||||
// algorithm (need the operator!)
|
||||
eoAlgo<EOT>& ga = make_algo_scalar(parser, state, eval, checkpoint, op);
|
||||
eoAlgo<EOT>& ga = make_algo_scalar(parser, state, eval, checkpoint, op, &dist);
|
||||
|
||||
///// End of construction of the algorith
|
||||
/////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@
|
|||
@param _chrom A binary chromosome
|
||||
*/
|
||||
|
||||
template <class Chrom> float binary_value(const Chrom& _chrom)
|
||||
template <class Chrom> double binary_value(const Chrom& _chrom)
|
||||
{
|
||||
float sum = 0;
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _chrom.size(); i++)
|
||||
if (_chrom[i])
|
||||
sum += _chrom[i];
|
||||
|
|
|
|||
Reference in a new issue