Adding Evolution Strategies:
src/es/eoEsGlobalXover.h and src/es/eoEsLocalXover.h for crossover src/es/make_XXX_es.h for user-input test/t-eoEsAll.cpp to test However, an old bug appeared: className was not const in eoGenOp (and derived classes) so I had to change that throughtout the hierarchy
This commit is contained in:
parent
4a152dc172
commit
10064ad967
28 changed files with 471 additions and 180 deletions
|
|
@ -10,7 +10,8 @@ libes_a_SOURCES = make_algo_scalar_real.cpp make_checkpoint_real.cpp \
|
|||
make_continue_real.cpp make_genotype_real.cpp \
|
||||
make_op_real.cpp make_pop_real.cpp make_run_real.cpp \
|
||||
make_algo_scalar_es.cpp make_checkpoint_es.cpp \
|
||||
make_continue_es.cpp make_pop_es.cpp make_run_es.cpp
|
||||
make_continue_es.cpp make_genotype_es.cpp \
|
||||
make_op_es.cpp make_pop_es.cpp make_run_es.cpp
|
||||
|
||||
CPPFLAGS = -Wall
|
||||
CXXFLAGS = -g
|
||||
|
|
|
|||
|
|
@ -27,13 +27,10 @@
|
|||
#ifndef _eoEsChromInit_H
|
||||
#define _eoEsChromInit_H
|
||||
|
||||
#include <utils/eoRealBounds.h>
|
||||
#include <es/eoRealInitBounded.h>
|
||||
#include <es/eoEsSimple.h>
|
||||
#include <es/eoEsStdev.h>
|
||||
#include <es/eoEsFull.h>
|
||||
#include <utils/eoRNG.h>
|
||||
|
||||
#include <eoInit.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
|
|
@ -44,90 +41,85 @@
|
|||
|
||||
Random Es-chromosome initializer (therefore derived from eoInit)
|
||||
|
||||
This class can initialize three types of Es's:
|
||||
This class can initialize four types of real-valued genotypes
|
||||
thanks to tempate specialization of private method create
|
||||
|
||||
eoEsSimple
|
||||
eoEsStdev
|
||||
eoEsFull
|
||||
eoReal just an eoVector<double>
|
||||
eoEsSimple + one self-adapting single sigma for all variables
|
||||
eoEsStdev a whole vector of self-adapting sigmas
|
||||
eoEsFull a full self-adapting correlation matrix
|
||||
|
||||
@see eoEsSimple eoEsStdev eoEsFull eoInit
|
||||
@see eoReal eoEsSimple eoEsStdev eoEsFull eoInit
|
||||
*/
|
||||
|
||||
template <class EOT>
|
||||
class eoEsChromInit : public eoInit<EOT>
|
||||
class eoEsChromInit : public eoRealInitBounded<EOT>
|
||||
{
|
||||
public :
|
||||
typedef typename EOT::Fitness FitT;
|
||||
typedef typename EOT::Fitness FitT;
|
||||
|
||||
eoEsChromInit(eoRealVectorBounds& _bounds) : bounds(_bounds)
|
||||
{}
|
||||
eoEsChromInit(eoRealVectorBounds& _bounds, double _sigma = 0.3) :
|
||||
eoRealInitBounded<EOT>(_bounds), sigma(_sigma) {}
|
||||
|
||||
void operator()(EOT& _eo)
|
||||
{
|
||||
create(_eo);
|
||||
}
|
||||
void operator()(EOT& _eo)
|
||||
{
|
||||
eoRealInitBounded<EOT>::operator()(_eo);
|
||||
create_self_adapt(_eo);
|
||||
_eo.invalidate(); // was MISSING!!!!
|
||||
}
|
||||
|
||||
// accessor to sigma
|
||||
double sigmaInit() {return sigma;}
|
||||
|
||||
private :
|
||||
|
||||
eoEsSimple<FitT>& create(eoEsSimple<FitT>& result)
|
||||
{
|
||||
result.resize(bounds.size());
|
||||
// No adaptive mutation at all
|
||||
void create_self_adapt(eoReal<FitT>& result)// security check :-)
|
||||
{
|
||||
throw runtime_error("We should not be in create_self_adapt(eoReal)!");
|
||||
}
|
||||
|
||||
bounds.uniform(result);
|
||||
// Adaptive mutation through a unique sigma
|
||||
void create_self_adapt(eoEsSimple<FitT>& result)
|
||||
{
|
||||
// sigma is scaled by the average range (if that means anything!)
|
||||
result.stdev = sigma;
|
||||
}
|
||||
|
||||
result.stdev = 0.3*bounds.averageRange(); // 0.3 should be read as a parameter
|
||||
// Adaptive mutation through a vector of sigmas
|
||||
void create_self_adapt(eoEsStdev<FitT>& result)
|
||||
{
|
||||
unsigned theSize = eoRealInitBounded<EOT>::size();
|
||||
result.stdevs.resize(theSize);
|
||||
for (unsigned i = 0; i < theSize; ++i)
|
||||
{
|
||||
// should we scale sigmas to the corresponding object variable range?
|
||||
result.stdevs[i] = sigma;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
// Adaptive mutation through a whole correlation matrix
|
||||
void create_self_adapt(eoEsFull<FitT>& result)
|
||||
{
|
||||
unsigned theSize = eoRealInitBounded<EOT>::size();
|
||||
|
||||
eoEsStdev<FitT> create(eoEsStdev<FitT>& result)
|
||||
{
|
||||
unsigned chromSize = bounds.size();
|
||||
result.resize(chromSize);
|
||||
result.stdevs.resize(chromSize);
|
||||
|
||||
bounds.uniform(result);
|
||||
for (unsigned i = 0; i < chromSize; ++i)
|
||||
{
|
||||
// uniformly in [0.2,0.4)
|
||||
// scaled by the range of the object variable)
|
||||
// Just a guess (anyone a better idea?)
|
||||
result.stdevs[i] = bounds.range(i) * (0.2 + 0.2*eo::rng.uniform());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
eoEsFull<FitT> create(eoEsFull<FitT>& result)
|
||||
{
|
||||
unsigned chromSize = bounds.size();
|
||||
result.resize(chromSize);
|
||||
result.stdevs.resize(chromSize);
|
||||
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < chromSize; ++i)
|
||||
{
|
||||
double length = bounds.maximum(i) - bounds.minimum(i);
|
||||
result[i] = bounds.minimum(i) + rng.uniform(length);
|
||||
result.stdevs.resize(theSize);
|
||||
for (unsigned i = 0; i < theSize; ++i)
|
||||
{
|
||||
// should we scale sigmas to the corresponding object variable range?
|
||||
result.stdevs[i] = sigma;
|
||||
}
|
||||
|
||||
// Just a guess at the stdevs (anyone a better idea?)
|
||||
result.stdevs[i] = rng.uniform(length);
|
||||
}
|
||||
|
||||
// nb of rotation angles: N*(N-1)/2 (in general!)
|
||||
result.correlations.resize(chromSize*(chromSize - 1) / 2);
|
||||
|
||||
for (i = 0; i < result.correlations.size(); ++i)
|
||||
{
|
||||
// And another random guess for random initialization
|
||||
result.correlations[i] = rng.uniform(2 * M_PI) - M_PI;
|
||||
}
|
||||
// nb of rotation angles: N*(N-1)/2 (in general!)
|
||||
result.correlations.resize(theSize*(theSize - 1) / 2);
|
||||
for (unsigned i = 0; i < result.correlations.size(); ++i)
|
||||
{
|
||||
// uniform in [-PI, PI)
|
||||
result.correlations[i] = rng.uniform(2 * M_PI) - M_PI;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
eoRealVectorBounds& bounds;
|
||||
double sigma; // initial value for sigmas
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class eoEsFull : public eoVector<Fit, double>
|
|||
|
||||
eoEsFull(void) : eoVector<Fit, double>() {}
|
||||
|
||||
std::string className(void) const { return "eoEsFull"; }
|
||||
virtual std::string className(void) const { return "eoEsFull"; }
|
||||
|
||||
void printOn(std::ostream& os) const
|
||||
{
|
||||
|
|
|
|||
139
eo/src/es/eoEsGlobalXover.h
Normal file
139
eo/src/es/eoEsGlobalXover.h
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoEsGlobalXover.h : ES global crossover
|
||||
// (c) 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 http://eeaax.cmap.polytchnique.fr/
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifndef _eoEsGlobalXover_H
|
||||
#define _eoEsGlobalXover_H
|
||||
|
||||
#include <utils/eoRNG.h>
|
||||
|
||||
#include <es/eoEsSimple.h>
|
||||
#include <es/eoEsStdev.h>
|
||||
#include <es/eoEsFull.h>
|
||||
|
||||
#include <eoGenOp.h>
|
||||
// needs a selector - here random
|
||||
#include <eoRandomSelect.h>
|
||||
|
||||
/** Gloabl crossover operator for ES genotypes.
|
||||
* Uses some Atom crossovers to handle both the object variables
|
||||
* and the mutation strategy parameters
|
||||
*/
|
||||
template<class EOT>
|
||||
class eoEsGlobalXover: public eoGenOp<EOT>
|
||||
{
|
||||
public:
|
||||
typedef typename EOT::Fitness FitT;
|
||||
|
||||
/**
|
||||
* (Default) Constructor.
|
||||
*/
|
||||
eoEsGlobalXover(eoBinOp<double> & _crossObj, eoBinOp<double> & _crossMut) :
|
||||
crossObj(_crossObj), crossMut(_crossMut) {}
|
||||
|
||||
/// The class name. Used to display statistics
|
||||
virtual string className() const { return "eoEsGlobalXover"; }
|
||||
|
||||
/// The TOTAL number of offspring (here = nb of parents modified in place)
|
||||
unsigned max_production(void) { return 1; }
|
||||
|
||||
/**
|
||||
* modifies one parents in the populator
|
||||
* using 2 new parents for each component!
|
||||
*
|
||||
* @param _pop a POPULATOR (not a simple population)
|
||||
*/
|
||||
void apply(eoPopulator<EOT>& _plop)
|
||||
{
|
||||
// First, select as many parents as you will have offspring
|
||||
EOT& parent = *_plop; // select the first parent
|
||||
|
||||
// first, the object variables
|
||||
for (unsigned i=0; i<parent.size(); i++)
|
||||
{
|
||||
// get extra parents - use private selector
|
||||
// _plop.source() is the eoPop<EOT> used by _plop to get parents
|
||||
const EOT& realParent1 = sel(_plop.source());
|
||||
const EOT& realParent2 = sel(_plop.source());
|
||||
parent[i] = realParent1[i];
|
||||
crossObj(parent[i], realParent2[i]); // apply eoBinOp
|
||||
}
|
||||
// then the self-adaptation parameters
|
||||
cross_self_adapt(parent, _plop.source());
|
||||
// dont' forget to invalidate
|
||||
parent.invalidate();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// the method to cross slef-adaptation parameters: need to specialize
|
||||
|
||||
void cross_self_adapt(eoEsSimple<FitT> & _parent, const eoPop<eoEsSimple<FitT> >& _pop)
|
||||
{
|
||||
const EOT& realParent1 = sel(_pop);
|
||||
const EOT& realParent2 = sel(_pop);
|
||||
_parent.stdev = realParent1.stdev;
|
||||
crossMut(_parent.stdev, realParent2.stdev); // apply eoBinOp
|
||||
}
|
||||
|
||||
void cross_self_adapt(eoEsStdev<FitT> & _parent, const eoPop<eoEsStdev<FitT> >& _pop)
|
||||
{
|
||||
for (unsigned i=0; i<_parent.size(); i++)
|
||||
{
|
||||
const EOT& realParent1 = sel(_pop);
|
||||
const EOT& realParent2 = sel(_pop);
|
||||
_parent.stdevs[i] = realParent1.stdevs[i];
|
||||
crossMut(_parent.stdevs[i], realParent2.stdevs[i]); // apply eoBinOp
|
||||
}
|
||||
}
|
||||
|
||||
void cross_self_adapt(eoEsFull<FitT> & _parent, const eoPop<eoEsFull<FitT> >& _pop)
|
||||
{
|
||||
unsigned i;
|
||||
// the StDev
|
||||
for (i=0; i<_parent.size(); i++)
|
||||
{
|
||||
const EOT& realParent1 = sel(_pop);
|
||||
const EOT& realParent2 = sel(_pop);
|
||||
_parent.stdevs[i] = realParent1.stdevs[i];
|
||||
crossMut(_parent.stdevs[i], realParent2.stdevs[i]); // apply eoBinOp
|
||||
}
|
||||
// the roataion angles
|
||||
for (i=0; i<_parent.correlations.size(); i++)
|
||||
{
|
||||
const EOT& realParent1 = sel(_pop);
|
||||
const EOT& realParent2 = sel(_pop);
|
||||
_parent.correlations[i] = realParent1.correlations[i];
|
||||
crossMut(_parent.correlations[i], realParent2.correlations[i]); // apply eoBinOp
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// the data
|
||||
eoRandomSelect<EOT> sel;
|
||||
eoBinOp<double> & crossObj;
|
||||
eoBinOp<double> & crossMut;
|
||||
};
|
||||
|
||||
#endif
|
||||
124
eo/src/es/eoEsLocalXover.h
Normal file
124
eo/src/es/eoEsLocalXover.h
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoEsLocalXover.h : ES global crossover
|
||||
// (c) 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 http://eeaax.cmap.polytchnique.fr/
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifndef _eoEsLocalXover_H
|
||||
#define _eoEsLocalXover_H
|
||||
|
||||
#include <utils/eoRNG.h>
|
||||
|
||||
#include <es/eoEsSimple.h>
|
||||
#include <es/eoEsStdev.h>
|
||||
#include <es/eoEsFull.h>
|
||||
|
||||
#include <eoGenOp.h>
|
||||
// needs a selector - here random
|
||||
#include <eoRandomSelect.h>
|
||||
|
||||
/** Local (i.e. std eoBinOp) crossover operator for ES genotypes.
|
||||
* Uses some Atom crossovers to handle both the object variables
|
||||
* and the mutation strategy parameters
|
||||
* It is an eoGenOp and not an eoBinOp for consistency with the global version
|
||||
*/
|
||||
template<class EOT>
|
||||
class eoEsLocalXover: public eoGenOp<EOT>
|
||||
{
|
||||
public:
|
||||
typedef typename EOT::Fitness FitT;
|
||||
|
||||
/**
|
||||
* (Default) Constructor.
|
||||
*/
|
||||
eoEsLocalXover(eoBinOp<double> & _crossObj, eoBinOp<double> & _crossMut) :
|
||||
crossObj(_crossObj), crossMut(_crossMut) {}
|
||||
|
||||
/// The class name. Used to display statistics
|
||||
virtual string className() const { return "eoEsLocalXover"; }
|
||||
|
||||
/// The TOTAL number of offspring (here = nb of parents modified in place)
|
||||
unsigned max_production(void) { return 1; }
|
||||
|
||||
/**
|
||||
* modifies one parents in the populator
|
||||
* using a second parent
|
||||
*
|
||||
* @param _pop a POPULATOR (not a simple population)
|
||||
*/
|
||||
void apply(eoPopulator<EOT>& _plop)
|
||||
{
|
||||
// First, select as many parents as you will have offspring
|
||||
EOT& parent1 = *_plop; // select the first parent
|
||||
const EOT& parent2 = sel(_plop.source()); // and the second, randomly
|
||||
|
||||
// first, the object variables
|
||||
for (unsigned i=0; i<parent1.size(); i++)
|
||||
{
|
||||
crossObj(parent1[i], parent2[i]); // apply eoBinOp
|
||||
}
|
||||
// then the self-adaptation parameters
|
||||
cross_self_adapt(parent1, parent2);
|
||||
// dont' forget to invalidate
|
||||
parent1.invalidate();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// the method to cross slef-adaptation parameters: need to specialize
|
||||
|
||||
void cross_self_adapt(eoEsSimple<FitT> & _parent1, const eoEsSimple<FitT> & _parent2)
|
||||
{
|
||||
crossMut(_parent1.stdev, _parent2.stdev); // apply eoBinOp
|
||||
}
|
||||
|
||||
void cross_self_adapt(eoEsStdev<FitT> & _parent1, const eoEsStdev<FitT> & _parent2)
|
||||
{
|
||||
for (unsigned i=0; i<_parent1.size(); i++)
|
||||
{
|
||||
crossMut(_parent1.stdevs[i], _parent2.stdevs[i]); // apply eoBinOp
|
||||
}
|
||||
}
|
||||
|
||||
void cross_self_adapt(eoEsFull<FitT> & _parent1, const eoEsFull<FitT> & _parent2)
|
||||
{
|
||||
unsigned i;
|
||||
// the StDev
|
||||
for (i=0; i<_parent1.size(); i++)
|
||||
{
|
||||
crossMut(_parent1.stdevs[i], _parent2.stdevs[i]); // apply eoBinOp
|
||||
}
|
||||
// the roataion angles
|
||||
for (i=0; i<_parent1.correlations.size(); i++)
|
||||
{
|
||||
crossMut(_parent1.correlations[i], _parent2.correlations[i]); // apply eoBinOp
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// the data
|
||||
eoRandomSelect<EOT> sel;
|
||||
eoBinOp<double> & crossObj;
|
||||
eoBinOp<double> & crossMut;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -122,11 +122,11 @@ public:
|
|||
|
||||
virtual bool operator()( eoEsStdev<FitT>& _eo )
|
||||
{
|
||||
double global = exp(TauGlb * rng.normal());
|
||||
double global = TauGlb * rng.normal();
|
||||
for (unsigned i = 0; i < _eo.size(); i++)
|
||||
{
|
||||
double stdev = _eo.stdevs[i];
|
||||
stdev *= global * exp(TauLcl * rng.normal());
|
||||
stdev *= exp( global + TauLcl * rng.normal() );
|
||||
|
||||
if (stdev < stdev_eps)
|
||||
stdev = stdev_eps;
|
||||
|
|
@ -135,7 +135,7 @@ public:
|
|||
_eo[i] += stdev * rng.normal();
|
||||
}
|
||||
|
||||
bounds.foldsInBounds(_eo);
|
||||
bounds.foldsInBounds(_eo);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -158,12 +158,12 @@ public:
|
|||
* First: mutate standard deviations (as above).
|
||||
*/
|
||||
|
||||
double global = exp(TauGlb * rng.normal());
|
||||
double global = TauGlb * rng.normal();
|
||||
unsigned i;
|
||||
for (i = 0; i < _eo.size(); i++)
|
||||
{
|
||||
double stdev = _eo.stdevs[i];
|
||||
stdev *= global * exp(TauLcl * rng.normal());
|
||||
stdev *= exp( global + TauLcl*rng.normal() );
|
||||
|
||||
if (stdev < stdev_eps)
|
||||
stdev = stdev_eps;
|
||||
|
|
@ -229,7 +229,8 @@ public:
|
|||
{
|
||||
unsigned size = bounds.size();
|
||||
TauLcl = _init.TauLcl();
|
||||
TauLcl /= sqrt((double) size);
|
||||
TauLcl /= sqrt(2*(double) size);
|
||||
cout << "Init<eoEsSimple>: tau local " << TauLcl << endl;
|
||||
}
|
||||
|
||||
void init(eoEsStdev<FitT>, eoEsMutationInit& _init)
|
||||
|
|
@ -242,12 +243,14 @@ public:
|
|||
// renormalization
|
||||
TauLcl /= sqrt( 2.0 * sqrt( (double)size ) );
|
||||
TauGlb /= sqrt( 2.0 * ( (double) size ) );
|
||||
cout << "Init<eoStDev>: tau local " << TauLcl << " et global " << TauGlb << endl;
|
||||
}
|
||||
|
||||
void init(eoEsFull<FitT>, eoEsMutationInit& _init)
|
||||
{
|
||||
init(eoEsStdev<FitT>(), _init);
|
||||
TauBeta = _init.TauBeta();
|
||||
cout << "Init<eoEsFull>: tau local " << TauLcl << " et global " << TauGlb << endl;
|
||||
}
|
||||
|
||||
// the data
|
||||
|
|
@ -264,14 +267,5 @@ public:
|
|||
template <class EOT>
|
||||
const double eoEsMutate<EOT>::stdev_eps = 1.0e-40;
|
||||
|
||||
/*
|
||||
* Correlated mutations in ESs, according to the following
|
||||
* sources:
|
||||
* H.-P. Schwefel: Internal Report of KFA Juelich, KFA-STE-IB-3/80
|
||||
* p. 43, 1980
|
||||
* G. Rudolph: Globale Optimierung mit parallelen Evolutions-
|
||||
* strategien, Diploma Thesis, University of Dortmund, 1990
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -47,13 +47,19 @@ class eoEsMutationInit
|
|||
{
|
||||
public :
|
||||
|
||||
eoEsMutationInit(eoParameterLoader& _parser) : parser(_parser), TauLclParam(0), TauGlbParam(0), TauBetaParam(0) {}
|
||||
eoEsMutationInit(eoParameterLoader& _parser,
|
||||
std::string _section="ES mutation parameters" ) :
|
||||
parser(_parser), repSection(_section),
|
||||
TauLclParam(0), TauGlbParam(0), TauBetaParam(0) {}
|
||||
|
||||
// because we have virtual function - size
|
||||
virtual ~eoEsMutationInit(){}
|
||||
|
||||
double TauLcl(void)
|
||||
{
|
||||
if (TauLclParam == 0)
|
||||
{
|
||||
TauLclParam = &parser.createParam(1.0, TauLclName(), "Local Tau", TauLclShort(), section());
|
||||
TauLclParam = &parser.createParam(1.0, TauLclName(), "Local Tau (before normalization)", TauLclShort(), section());
|
||||
}
|
||||
|
||||
return TauLclParam->value();
|
||||
|
|
@ -63,7 +69,7 @@ class eoEsMutationInit
|
|||
{
|
||||
if (TauGlbParam == 0)
|
||||
{
|
||||
TauGlbParam = &parser.createParam(1.0, TauGlbName(), "Global Tau", TauGlbShort(), section());
|
||||
TauGlbParam = &parser.createParam(1.0, TauGlbName(), "Global Tau (before normalization)", TauGlbShort(), section());
|
||||
}
|
||||
|
||||
return TauGlbParam->value();
|
||||
|
|
@ -82,7 +88,7 @@ class eoEsMutationInit
|
|||
protected :
|
||||
|
||||
virtual std::string section(void)
|
||||
{ return "Parameters of ES mutation (before renormalization)"; }
|
||||
{ return repSection; }
|
||||
|
||||
virtual std::string TauLclName(void) const { return "TauLcL"; }
|
||||
virtual char TauLclShort(void) const { return 'l'; }
|
||||
|
|
@ -95,11 +101,11 @@ class eoEsMutationInit
|
|||
|
||||
private :
|
||||
|
||||
eoParameterLoader& parser;
|
||||
|
||||
eoValueParam<double>* TauLclParam;
|
||||
eoValueParam<double>* TauGlbParam;
|
||||
eoValueParam<double>* TauBetaParam;
|
||||
eoParameterLoader& parser;
|
||||
std::string repSection;
|
||||
eoValueParam<double>* TauLclParam;
|
||||
eoValueParam<double>* TauGlbParam;
|
||||
eoValueParam<double>* TauBetaParam;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public :
|
|||
|
||||
eoEsSimple(void) : eoVector<Fit, double>() {}
|
||||
|
||||
std::string className(void) const { return "eoEsSimple"; }
|
||||
virtual std::string className(void) const { return "eoEsSimple"; }
|
||||
|
||||
void printOn(std::ostream& os) const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class eoEsStdev : public eoVector<Fit, double>
|
|||
|
||||
eoEsStdev(void) : eoVector<Fit, double>() {}
|
||||
|
||||
std::string className(void) const { return "eoEsStdev"; }
|
||||
virtual std::string className(void) const { return "eoEsStdev"; }
|
||||
|
||||
void printOn(std::ostream& os) const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public :
|
|||
eoQuadOp<vector<double> > & _stdDevXOver) :
|
||||
objectXOver(_objectXOver), stdDevXOver(_stdDevXOver) {}
|
||||
|
||||
std::string className(void) const { return "eoEsStdevXOver"; }
|
||||
virtual std::string className(void) const { return "eoEsStdevXOver"; }
|
||||
|
||||
bool operator()(EOT & _eo1, EOT & _eo2)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ template<class EOT> class eoGenericUniformMutation: public eoMonOp<EOT>
|
|||
bounds(_bounds), epsilon(_epsilon), p_change(_p_change) {}
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoGenericUniformMutation"; }
|
||||
virtual string className() const { return "eoGenericUniformMutation"; }
|
||||
|
||||
/**
|
||||
* Do it!
|
||||
|
|
@ -140,7 +140,7 @@ template<class EOT> class eoGenericDetUniformMutation:
|
|||
bounds(_bounds), epsilon(_epsilon), no(_no) {}
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoGenericDetUniformMutation"; }
|
||||
virtual string className() const { return "eoGenericDetUniformMutation"; }
|
||||
|
||||
/**
|
||||
* Do it!
|
||||
|
|
@ -208,7 +208,7 @@ template<class EOT> class eoGenericSegmentCrossover: public eoQuadOp<EOT>
|
|||
bounds(_bounds), alpha(_alpha), range(1+2*_alpha) {}
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoGenericSegmentCrossover"; }
|
||||
virtual string className() const { return "eoGenericSegmentCrossover"; }
|
||||
|
||||
/**
|
||||
* segment crossover - modifies both parents
|
||||
|
|
@ -307,7 +307,7 @@ template<class EOT> class eoGenericArithmeticCrossover:
|
|||
}
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoGenericArithmeticCrossover"; }
|
||||
virtual string className() const { return "eoGenericArithmeticCrossover"; }
|
||||
|
||||
/**
|
||||
* arithmetical crossover - modifies both parents
|
||||
|
|
@ -383,7 +383,7 @@ template<class EOT> class eoGenericRealUxOver: public eoQuadOp<EOT>
|
|||
}
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoRealUxOver"; }
|
||||
virtual string className() const { return "eoRealUxOver"; }
|
||||
|
||||
/**
|
||||
* Uniform crossover for real vectors
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ template<class EOT> class eoNormalMutation: public eoMonOp<EOT>
|
|||
sigma(_sigma), bounds(_bounds), p_change(_p_change) {}
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoNormalMutation"; }
|
||||
virtual string className() const { return "eoNormalMutation"; }
|
||||
|
||||
/**
|
||||
* Do it!
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ template <class FitT> class eoReal: public eoVector<FitT, double>
|
|||
eoVector<FitT, double>(size, value) {}
|
||||
|
||||
/// My class name.
|
||||
string className() const
|
||||
virtual string className() const
|
||||
{
|
||||
return "eoReal";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,21 +33,30 @@
|
|||
#include <es/eoReal.h>
|
||||
#include <utils/eoRealBounds.h>
|
||||
|
||||
template <class FitT>
|
||||
class eoRealInitBounded : public eoInit<eoReal<FitT> >
|
||||
/** Simple initialization for any EOT that derives from vector<double>
|
||||
* uniformly in some bounds
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoRealInitBounded : public eoInit<EOT>
|
||||
{
|
||||
public:
|
||||
/** Ctor - from eoRealVectorBounds */
|
||||
eoRealInitBounded(eoRealVectorBounds & _bounds):bounds(_bounds) {}
|
||||
eoRealInitBounded(eoRealVectorBounds & _bounds):bounds(_bounds)
|
||||
{
|
||||
if (!bounds.isBounded())
|
||||
throw runtime_error("Needs bounded bounds to initialize a vector<double>");
|
||||
}
|
||||
|
||||
/** simply passes the argument to the uniform method of the bounds */
|
||||
virtual void operator()(eoReal<FitT>& _eo)
|
||||
virtual void operator()(EOT & _eo)
|
||||
{
|
||||
bounds.uniform(_eo); // fills _eo with uniform values in bounds
|
||||
bounds.uniform(_eo); // resizes, and fills uniformly in bounds
|
||||
_eo.invalidate(); // was MISSING!!!!
|
||||
}
|
||||
|
||||
/** accessor to the bounds */
|
||||
const eoRealVectorBounds & theBounds() {return bounds;}
|
||||
virtual eoRealVectorBounds & theBounds() {return bounds;}
|
||||
virtual unsigned size(){return bounds.size();}
|
||||
|
||||
private:
|
||||
eoRealVectorBounds & bounds;
|
||||
|
|
@ -55,5 +64,5 @@ class eoRealInitBounded : public eoInit<eoReal<FitT> >
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
//@}
|
||||
#endif eoRealOp_h
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ template<class EOT> class eoUniformMutation: public eoMonOp<EOT>
|
|||
p_change(_p_change) {}
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoUniformMutation"; }
|
||||
virtual string className() const { return "eoUniformMutation"; }
|
||||
|
||||
/**
|
||||
* Do it!
|
||||
|
|
@ -191,7 +191,7 @@ template<class EOT> class eoDetUniformMutation: public eoMonOp<EOT>
|
|||
}
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoDetUniformMutation"; }
|
||||
virtual string className() const { return "eoDetUniformMutation"; }
|
||||
|
||||
/**
|
||||
* Do it!
|
||||
|
|
@ -273,7 +273,7 @@ template<class EOT> class eoSegmentCrossover: public eoQuadOp<EOT>
|
|||
bounds(_bounds), alpha(_alpha), range(1+2*_alpha) {}
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoSegmentCrossover"; }
|
||||
virtual string className() const { return "eoSegmentCrossover"; }
|
||||
|
||||
/**
|
||||
* segment crossover - modifies both parents
|
||||
|
|
@ -371,7 +371,7 @@ template<class EOT> class eoArithmeticCrossover: public eoQuadOp<EOT>
|
|||
}
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoArithmeticCrossover"; }
|
||||
virtual string className() const { return "eoArithmeticCrossover"; }
|
||||
|
||||
/**
|
||||
* arithmetical crossover - modifies both parents
|
||||
|
|
@ -448,7 +448,7 @@ template<class EOT> class eoRealUxOver: public eoQuadOp<EOT>
|
|||
}
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoRealUxOver"; }
|
||||
virtual string className() const { return "eoRealUxOver"; }
|
||||
|
||||
/**
|
||||
* Uniform crossover for real vectors
|
||||
|
|
|
|||
|
|
@ -57,18 +57,31 @@
|
|||
#include <es/eoEsStdev.h> // one sigmal per object variable
|
||||
#include <es/eoEsFull.h> // full correlation matrix per indi
|
||||
|
||||
// include all similar declaration for eoReal - i.e. real-valued genotyes
|
||||
// without self-adaptation
|
||||
#include <es/make_real.h>
|
||||
|
||||
//Representation dependent - rewrite everything anew for each representation
|
||||
//////////////////////////
|
||||
|
||||
/*
|
||||
// the genotypes
|
||||
eoInit<eoEsSimple<double> > & make_genotype(eoParameterLoader& _parser, eoState& _state, double _d);
|
||||
eoInit<eoEsSimple<eoMinimizingFitness> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoMinimizingFitness _d);
|
||||
eoRealInitBounded<eoEsSimple<double> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoEsSimple<double> _eo);
|
||||
eoRealInitBounded<eoEsSimple<eoMinimizingFitness> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoEsSimple<eoMinimizingFitness> _eo);
|
||||
|
||||
eoRealInitBounded<eoEsStdev<double> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoEsStdev<double> _eo);
|
||||
eoRealInitBounded<eoEsStdev<eoMinimizingFitness> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoEsStdev<eoMinimizingFitness> _eo);
|
||||
|
||||
eoRealInitBounded<eoEsFull<double> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoEsFull<double> _eo);
|
||||
eoRealInitBounded<eoEsFull<eoMinimizingFitness> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoEsFull<eoMinimizingFitness> _eo);
|
||||
|
||||
|
||||
|
||||
// the operators
|
||||
eoGenOp<eoEsStdev<double> >& make_op(eoParameterLoader& _parser, eoState& _state, eoInit<eoEsStdev<double> >& _init);
|
||||
eoGenOp<eoEsStdev<eoMinimizingFitness> >& make_op(eoParameterLoader& _parser, eoState& _state, eoInit<eoEsStdev<eoMinimizingFitness> >& _init);
|
||||
*/
|
||||
eoGenOp<eoEsSimple<double> >& make_op(eoParameterLoader& _parser, eoState& _state, eoRealInitBounded<eoEsSimple<double> >& _init);
|
||||
eoGenOp<eoEsSimple<eoMinimizingFitness> >& make_op(eoParameterLoader& _parser, eoState& _state, eoRealInitBounded<eoEsSimple<eoMinimizingFitness> >& _init);
|
||||
eoGenOp<eoEsStdev<double> >& make_op(eoParameterLoader& _parser, eoState& _state, eoRealInitBounded<eoEsStdev<double> >& _init);
|
||||
eoGenOp<eoEsStdev<eoMinimizingFitness> >& make_op(eoParameterLoader& _parser, eoState& _state, eoRealInitBounded<eoEsStdev<eoMinimizingFitness> >& _init);
|
||||
eoGenOp<eoEsFull<double> >& make_op(eoParameterLoader& _parser, eoState& _state, eoRealInitBounded<eoEsFull<double> >& _init);
|
||||
eoGenOp<eoEsFull<eoMinimizingFitness> >& make_op(eoParameterLoader& _parser, eoState& _state, eoRealInitBounded<eoEsFull<eoMinimizingFitness> >& _init);
|
||||
|
||||
//Representation INdependent
|
||||
////////////////////////////
|
||||
|
|
|
|||
|
|
@ -52,11 +52,11 @@
|
|||
|
||||
/// The following function merely call the templatized do_* functions
|
||||
|
||||
eoInit<eoReal<double> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoReal<double> _eo)
|
||||
eoEsChromInit<eoReal<double> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoReal<double> _eo)
|
||||
{
|
||||
return do_make_genotype(_parser, _state, _eo);
|
||||
}
|
||||
eoInit<eoReal<eoMinimizingFitness> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoReal<eoMinimizingFitness> _eo)
|
||||
eoEsChromInit<eoReal<eoMinimizingFitness> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoReal<eoMinimizingFitness> _eo)
|
||||
{
|
||||
return do_make_genotype(_parser, _state, _eo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
#define _make_genotype_h
|
||||
|
||||
#include <es/eoReal.h>
|
||||
#include <eoRealInitBounded.h>
|
||||
#include <eoEsChromInit.h>
|
||||
// also need the parser and param includes
|
||||
#include <utils/eoParser.h>
|
||||
#include <utils/eoState.h>
|
||||
|
|
@ -58,7 +58,7 @@
|
|||
*/
|
||||
|
||||
template <class EOT>
|
||||
eoInit<EOT> & do_make_genotype(eoParameterLoader& _parser, eoState& _state, EOT)
|
||||
eoEsChromInit<EOT> & do_make_genotype(eoParameterLoader& _parser, eoState& _state, EOT)
|
||||
{
|
||||
// the fitness type
|
||||
typedef typename EOT::Fitness FitT;
|
||||
|
|
@ -88,8 +88,16 @@ eoInit<EOT> & do_make_genotype(eoParameterLoader& _parser, eoState& _state, EOT)
|
|||
throw runtime_error("Sorry, only unique bounds for all variables implemented at the moment. Come back later");
|
||||
// we need to give ownership of this pointer to somebody
|
||||
|
||||
eoRealInitBounded<FitT> * init =
|
||||
new eoRealInitBounded<FitT>(*ptBounds);
|
||||
// now some initial value for sigmas - even if useless?
|
||||
// shoudl be used in Normal mutation
|
||||
eoValueParam<double>& sigmaParam = _parser.createParam(0.3, "sigmaInit", "Initial value for Sigma(s)", 's',"initialization");
|
||||
|
||||
// minimum check
|
||||
if ( (sigmaParam.value() < 0) )
|
||||
throw runtime_error("Invalid sigma");
|
||||
|
||||
eoEsChromInit<EOT> * init =
|
||||
new eoEsChromInit<EOT>(*ptBounds, sigmaParam.value());
|
||||
// satore in state
|
||||
_state.storeFunctor(init);
|
||||
return *init;
|
||||
|
|
|
|||
|
|
@ -37,18 +37,18 @@
|
|||
*/
|
||||
|
||||
// Templatized code
|
||||
#include <es/make_op.h>
|
||||
#include <es/make_op_real.h>
|
||||
|
||||
/// The following function merely call the templatized do_* functions above
|
||||
|
||||
// oeprators
|
||||
////////////
|
||||
eoGenOp<eoReal<double> >& make_op(eoParameterLoader& _parser, eoState& _state, eoInit<eoReal<double> >& _init)
|
||||
eoGenOp<eoReal<double> >& make_op(eoParameterLoader& _parser, eoState& _state, eoRealInitBounded<eoReal<double> >& _init)
|
||||
{
|
||||
return do_make_op(_parser, _state, _init);
|
||||
}
|
||||
|
||||
eoGenOp<eoReal<eoMinimizingFitness> >& make_op(eoParameterLoader& _parser, eoState& _state, eoInit<eoReal<eoMinimizingFitness> >& _init)
|
||||
eoGenOp<eoReal<eoMinimizingFitness> >& make_op(eoParameterLoader& _parser, eoState& _state, eoRealInitBounded<eoReal<eoMinimizingFitness> >& _init)
|
||||
{
|
||||
return do_make_op(_parser, _state, _init);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,18 +53,19 @@
|
|||
#include <eoGenOp.h>
|
||||
#include <eoPop.h>
|
||||
|
||||
#include <es/eoRealInitBounded.h>
|
||||
#include <es/eoReal.h>
|
||||
|
||||
//Representation dependent - rewrite everything anew for each representation
|
||||
//////////////////////////
|
||||
|
||||
// the genotypes
|
||||
eoInit<eoReal<double> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoReal<double> _eo);
|
||||
eoInit<eoReal<eoMinimizingFitness> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoReal<eoMinimizingFitness> _eo);
|
||||
eoRealInitBounded<eoReal<double> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoReal<double> _eo);
|
||||
eoRealInitBounded<eoReal<eoMinimizingFitness> > & make_genotype(eoParameterLoader& _parser, eoState& _state, eoReal<eoMinimizingFitness> _eo);
|
||||
|
||||
// the operators
|
||||
eoGenOp<eoReal<double> >& make_op(eoParameterLoader& _parser, eoState& _state, eoInit<eoReal<double> >& _init);
|
||||
eoGenOp<eoReal<eoMinimizingFitness> >& make_op(eoParameterLoader& _parser, eoState& _state, eoInit<eoReal<eoMinimizingFitness> >& _init);
|
||||
eoGenOp<eoReal<double> >& make_op(eoParameterLoader& _parser, eoState& _state, eoRealInitBounded<eoReal<double> >& _init);
|
||||
eoGenOp<eoReal<eoMinimizingFitness> >& make_op(eoParameterLoader& _parser, eoState& _state, eoRealInitBounded<eoReal<eoMinimizingFitness> >& _init);
|
||||
|
||||
//Representation INdependent
|
||||
////////////////////////////
|
||||
|
|
|
|||
Reference in a new issue