use adaptive operators to implement CMA-ES
This commit is contained in:
parent
fc66eb4fd7
commit
546f24295e
1 changed files with 36 additions and 28 deletions
|
|
@ -41,8 +41,8 @@ Authors:
|
||||||
#include "Sphere.h"
|
#include "Sphere.h"
|
||||||
|
|
||||||
|
|
||||||
typedef eoReal<eoMinimizingFitness> EOT;
|
typedef eoReal<eoMinimizingFitness> RealVec;
|
||||||
typedef edoNormalMulti< EOT > Distrib;
|
typedef edoNormalAdaptive< RealVec > Distrib;
|
||||||
|
|
||||||
|
|
||||||
int main(int ac, char** av)
|
int main(int ac, char** av)
|
||||||
|
|
@ -59,24 +59,32 @@ int main(int ac, char** av)
|
||||||
// Instantiate all needed parameters for EDA algorithm
|
// Instantiate all needed parameters for EDA algorithm
|
||||||
double selection_rate = parser.createParam((double)0.5, "selection_rate", "Selection Rate", 'R', section).value(); // R
|
double selection_rate = parser.createParam((double)0.5, "selection_rate", "Selection Rate", 'R', section).value(); // R
|
||||||
|
|
||||||
eoSelect< EOT >* selector = new eoDetSelect< EOT >( selection_rate );
|
unsigned long max_eval = parser.getORcreateParam((unsigned long)0, "maxEval", "Maximum number of evaluations (0 = none)", 'E', "Stopping criterion").value(); // E
|
||||||
|
|
||||||
|
unsigned int dim = parser.createParam((unsigned int)10, "dimension-size", "Dimension size", 'd', section).value(); // d
|
||||||
|
|
||||||
|
|
||||||
|
double mu = dim / 2;
|
||||||
|
|
||||||
|
|
||||||
|
edoNormalAdaptive<RealVec> distribution(dim);
|
||||||
|
|
||||||
|
eoSelect< RealVec >* selector = new eoDetSelect< RealVec >( selection_rate );
|
||||||
state.storeFunctor(selector);
|
state.storeFunctor(selector);
|
||||||
|
|
||||||
edoEstimator< Distrib >* estimator = new edoEstimatorNormalMulti< EOT >();
|
edoEstimator< Distrib >* estimator = new edoEstimatorNormalAdaptive<RealVec>( distribution, mu );
|
||||||
state.storeFunctor(estimator);
|
state.storeFunctor(estimator);
|
||||||
|
|
||||||
eoEvalFunc< EOT >* plainEval = new Rosenbrock< EOT >();
|
eoEvalFunc< RealVec >* plainEval = new Rosenbrock< RealVec >();
|
||||||
state.storeFunctor(plainEval);
|
state.storeFunctor(plainEval);
|
||||||
|
|
||||||
unsigned long max_eval = parser.getORcreateParam((unsigned long)0, "maxEval", "Maximum number of evaluations (0 = none)", 'E', "Stopping criterion").value(); // E
|
eoEvalFuncCounterBounder< RealVec > eval(*plainEval, max_eval);
|
||||||
eoEvalFuncCounterBounder< EOT > eval(*plainEval, max_eval);
|
|
||||||
|
|
||||||
eoRndGenerator< double >* gen = new eoUniformGenerator< double >(-5, 5);
|
eoRndGenerator< double >* gen = new eoUniformGenerator< double >(-5, 5);
|
||||||
state.storeFunctor(gen);
|
state.storeFunctor(gen);
|
||||||
|
|
||||||
unsigned int dimension_size = parser.createParam((unsigned int)10, "dimension-size", "Dimension size", 'd', section).value(); // d
|
|
||||||
|
|
||||||
eoInitFixedLength< EOT >* init = new eoInitFixedLength< EOT >( dimension_size, *gen );
|
eoInitFixedLength< RealVec >* init = new eoInitFixedLength< RealVec >( dim, *gen );
|
||||||
state.storeFunctor(init);
|
state.storeFunctor(init);
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -84,27 +92,27 @@ int main(int ac, char** av)
|
||||||
// Generation of population from do_make_pop (creates parameters, manages persistance and so on...)
|
// Generation of population from do_make_pop (creates parameters, manages persistance and so on...)
|
||||||
// ... and creates the parameters: L P r S
|
// ... and creates the parameters: L P r S
|
||||||
// this first sampler creates a uniform distribution independently from our distribution (it does not use edoUniform).
|
// this first sampler creates a uniform distribution independently from our distribution (it does not use edoUniform).
|
||||||
eoPop< EOT >& pop = do_make_pop(parser, state, *init);
|
eoPop< RealVec >& pop = do_make_pop(parser, state, *init);
|
||||||
|
|
||||||
// (2) First evaluation before starting the research algorithm
|
// (2) First evaluation before starting the research algorithm
|
||||||
apply(eval, pop);
|
apply(eval, pop);
|
||||||
|
|
||||||
// Prepare bounder class to set bounds of sampling.
|
// Prepare bounder class to set bounds of sampling.
|
||||||
// This is used by edoSampler.
|
// This is used by edoSampler.
|
||||||
edoBounder< EOT >* bounder =
|
edoBounder< RealVec >* bounder =
|
||||||
new edoBounderRng< EOT >( EOT(pop[0].size(), -5), EOT(pop[0].size(), 5), *gen); // FIXME do not use hard-coded bounds
|
new edoBounderRng< RealVec >( RealVec(dim, -5), RealVec(dim, 5), *gen); // FIXME do not use hard-coded bounds
|
||||||
state.storeFunctor(bounder);
|
state.storeFunctor(bounder);
|
||||||
|
|
||||||
// Prepare sampler class with a specific distribution
|
// Prepare sampler class with a specific distribution
|
||||||
edoSampler< Distrib >* sampler = new edoSamplerNormalMulti< EOT >( *bounder );
|
edoSampler< Distrib >* sampler = new edoSamplerNormalAdaptive< RealVec >( *bounder );
|
||||||
state.storeFunctor(sampler);
|
state.storeFunctor(sampler);
|
||||||
|
|
||||||
// stopping criteria
|
// stopping criteria
|
||||||
// ... and creates the parameter letters: C E g G s T
|
// ... and creates the parameter letters: C E g G s T
|
||||||
eoContinue< EOT >& eo_continue = do_make_continue(parser, state, eval);
|
eoContinue< RealVec >& eo_continue = do_make_continue(parser, state, eval);
|
||||||
|
|
||||||
// population output
|
// population output
|
||||||
eoCheckPoint< EOT >& pop_continue = do_make_checkpoint(parser, state, eval, eo_continue);
|
eoCheckPoint< RealVec >& pop_continue = do_make_checkpoint(parser, state, eval, eo_continue);
|
||||||
|
|
||||||
// distribution output
|
// distribution output
|
||||||
edoDummyContinue< Distrib >* dummy_continue = new edoDummyContinue< Distrib >();
|
edoDummyContinue< Distrib >* dummy_continue = new edoDummyContinue< Distrib >();
|
||||||
|
|
@ -115,7 +123,7 @@ int main(int ac, char** av)
|
||||||
|
|
||||||
// eoEPRemplacement causes the using of the current and previous
|
// eoEPRemplacement causes the using of the current and previous
|
||||||
// sample for sampling.
|
// sample for sampling.
|
||||||
eoReplacement< EOT >* replacor = new eoEPReplacement< EOT >(pop.size());
|
eoReplacement< RealVec >* replacor = new eoEPReplacement< RealVec >(pop.size());
|
||||||
state.storeFunctor(replacor);
|
state.storeFunctor(replacor);
|
||||||
|
|
||||||
// Some stuff to display helper when we are using -h option
|
// Some stuff to display helper when we are using -h option
|
||||||
|
|
@ -133,7 +141,7 @@ int main(int ac, char** av)
|
||||||
//
|
//
|
||||||
// FIXME: theses objects are instanciated there in order to avoid a folder
|
// FIXME: theses objects are instanciated there in order to avoid a folder
|
||||||
// removing as edoFileSnapshot does within ctor.
|
// removing as edoFileSnapshot does within ctor.
|
||||||
edoPopStat< EOT >* popStat = new edoPopStat<EOT>;
|
edoPopStat< RealVec >* popStat = new edoPopStat<RealVec>;
|
||||||
state.storeFunctor(popStat);
|
state.storeFunctor(popStat);
|
||||||
pop_continue.add(*popStat);
|
pop_continue.add(*popStat);
|
||||||
|
|
||||||
|
|
@ -143,10 +151,10 @@ int main(int ac, char** av)
|
||||||
pop_continue.add(*fileSnapshot);
|
pop_continue.add(*fileSnapshot);
|
||||||
|
|
||||||
// distribution output (after helper)
|
// distribution output (after helper)
|
||||||
edoDistribStat< Distrib >* distrib_stat = new edoStatNormalMulti< EOT >();
|
// edoDistribStat< Distrib >* distrib_stat = new edoStatNormalAdaptive< RealVec >();
|
||||||
state.storeFunctor(distrib_stat);
|
// state.storeFunctor(distrib_stat);
|
||||||
|
|
||||||
distribution_continue->add( *distrib_stat );
|
// distribution_continue->add( *distrib_stat );
|
||||||
|
|
||||||
// eoMonitor* stdout_monitor = new eoStdoutMonitor();
|
// eoMonitor* stdout_monitor = new eoStdoutMonitor();
|
||||||
// state.storeFunctor(stdout_monitor);
|
// state.storeFunctor(stdout_monitor);
|
||||||
|
|
@ -155,14 +163,14 @@ int main(int ac, char** av)
|
||||||
|
|
||||||
eoFileMonitor* file_monitor = new eoFileMonitor("eda_distribution_bounds.txt");
|
eoFileMonitor* file_monitor = new eoFileMonitor("eda_distribution_bounds.txt");
|
||||||
state.storeFunctor(file_monitor);
|
state.storeFunctor(file_monitor);
|
||||||
file_monitor->add(*distrib_stat);
|
// file_monitor->add(*distrib_stat);
|
||||||
distribution_continue->add( *file_monitor );
|
distribution_continue->add( *file_monitor );
|
||||||
|
|
||||||
eoPopLoopEval<EOT> popEval( eval );
|
eoPopLoopEval<RealVec> popEval( eval );
|
||||||
|
|
||||||
// EDA algorithm configuration
|
// EDA algorithm configuration
|
||||||
edoAlgo< Distrib >* algo = new edoEDA< Distrib >
|
edoAlgo< Distrib >* algo = new edoCMAES< Distrib >
|
||||||
(popEval, *selector, *estimator, *sampler, *replacor,
|
(distribution, popEval, *selector, *estimator, *sampler, *replacor,
|
||||||
pop_continue, *distribution_continue );
|
pop_continue, *distribution_continue );
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue