update the edoEDA to a simple EDA
This commit is contained in:
parent
37390e64dc
commit
c63e5f919f
3 changed files with 98 additions and 338 deletions
|
|
@ -52,32 +52,19 @@ int main(int ac, char** av)
|
|||
// Letters used by the following declarations:
|
||||
// a d i p t
|
||||
|
||||
std::string section("Algorithm parameters");
|
||||
|
||||
// FIXME: default value to check
|
||||
//double initial_temperature = parser.createParam((double)10e5, "temperature", "Initial temperature", 'i', section).value(); // i
|
||||
std::string section("Algorithm parameters");
|
||||
|
||||
eoState state;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Instantiate all needed parameters for EDA algorithm
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
double selection_rate = parser.createParam((double)0.5, "selection_rate", "Selection Rate", 'R', section).value(); // R
|
||||
|
||||
eoSelect< EOT >* selector = new eoDetSelect< EOT >( selection_rate );
|
||||
state.storeFunctor(selector);
|
||||
|
||||
edoEstimator< Distrib >* estimator = new edoEstimatorNormalMulti< EOT >();
|
||||
edoEstimator< Distrib >* estimator = new edoEstimatorNormalMulti< EOT >();
|
||||
state.storeFunctor(estimator);
|
||||
|
||||
eoSelectOne< EOT >* selectone = new eoDetTournamentSelect< EOT >( 2 );
|
||||
state.storeFunctor(selectone);
|
||||
|
||||
edoModifierMass< Distrib >* modifier = new edoNormalMultiCenter< EOT >();
|
||||
state.storeFunctor(modifier);
|
||||
|
||||
eoEvalFunc< EOT >* plainEval = new Rosenbrock< EOT >();
|
||||
state.storeFunctor(plainEval);
|
||||
|
||||
|
|
@ -87,159 +74,65 @@ int main(int ac, char** av)
|
|||
eoRndGenerator< double >* gen = new eoUniformGenerator< double >(-5, 5);
|
||||
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 );
|
||||
state.storeFunctor(init);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// (1) Population init and sampler
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Generation of population from do_make_pop (creates parameters, manages persistance and so on...)
|
||||
// ... and creates the parameters: L P r S
|
||||
|
||||
// this first sampler creates a uniform distribution independently from our distribution (it does not use doUniform).
|
||||
|
||||
// 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);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// (2) First evaluation before starting the research algorithm
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
apply(eval, pop);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Prepare bounder class to set bounds of sampling.
|
||||
// This is used by doSampler.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
edoBounder< EOT >* bounder = new edoBounderRng< EOT >(EOT(pop[0].size(), -5),
|
||||
EOT(pop[0].size(), 5),
|
||||
*gen);
|
||||
// This is used by edoSampler.
|
||||
edoBounder< EOT >* bounder =
|
||||
new edoBounderRng< EOT >( EOT(pop[0].size(), -5), EOT(pop[0].size(), 5), *gen); // FIXME do not use hard-coded bounds
|
||||
state.storeFunctor(bounder);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Prepare sampler class with a specific distribution
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
edoSampler< Distrib >* sampler = new edoSamplerNormalMulti< EOT >( *bounder );
|
||||
state.storeFunctor(sampler);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Metropolis sample parameters
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//unsigned int popSize = parser.getORcreateParam((unsigned int)20, "popSize", "Population Size", 'P', "Evolution Engine").value();
|
||||
|
||||
//moContinuator< moDummyNeighbor<EOT> >* sa_continue = new moIterContinuator< moDummyNeighbor<EOT> >( popSize );
|
||||
//state.storeFunctor(sa_continue);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// SA parameters
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//double threshold_temperature = parser.createParam((double)0.1, "threshold", "Minimal temperature at which stop", 't', section).value(); // t
|
||||
//double alpha = parser.createParam((double)0.1, "alpha", "Temperature decrease rate", 'a', section).value(); // a
|
||||
|
||||
//moCoolingSchedule<EOT>* cooling_schedule = new moSimpleCoolingSchedule<EOT>(initial_temperature, alpha, 0, threshold_temperature);
|
||||
//state.storeFunctor(cooling_schedule);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// stopping criteria
|
||||
// ... and creates the parameter letters: C E g G s T
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
eoContinue< EOT >& eo_continue = do_make_continue(parser, state, eval);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// population output
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
eoCheckPoint< EOT >& pop_continue = do_make_checkpoint(parser, state, eval, eo_continue);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// distribution output
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
edoDummyContinue< Distrib >* dummy_continue = new edoDummyContinue< Distrib >();
|
||||
state.storeFunctor(dummy_continue);
|
||||
|
||||
edoCheckPoint< Distrib >* distribution_continue = new edoCheckPoint< Distrib >( *dummy_continue );
|
||||
state.storeFunctor(distribution_continue);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoEPRemplacement causes the using of the current and previous
|
||||
// sample for sampling.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
eoReplacement< EOT >* replacor = new eoEPReplacement< EOT >(pop.size());
|
||||
|
||||
// Below, use eoGenerationalReplacement to sample only on the current sample
|
||||
|
||||
//eoReplacement< EOT >* replacor = new eoGenerationalReplacement< EOT >(); // FIXME: to define the size
|
||||
|
||||
state.storeFunctor(replacor);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Some stuff to display helper when we are using -h option
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(std::cout);
|
||||
exit(1);
|
||||
}
|
||||
{
|
||||
parser.printHelp(std::cout);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Help + Verbose routines
|
||||
|
||||
make_verbose(parser);
|
||||
make_help(parser);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// population output (after helper)
|
||||
//
|
||||
// FIXME: theses objects are instanciate there in order to avoid a folder
|
||||
// removing as doFileSnapshot does within ctor.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// FIXME: theses objects are instanciated there in order to avoid a folder
|
||||
// removing as edoFileSnapshot does within ctor.
|
||||
edoPopStat< EOT >* popStat = new edoPopStat<EOT>;
|
||||
state.storeFunctor(popStat);
|
||||
pop_continue.add(*popStat);
|
||||
|
|
@ -249,13 +142,7 @@ int main(int ac, char** av)
|
|||
fileSnapshot->add(*popStat);
|
||||
pop_continue.add(*fileSnapshot);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// distribution output (after helper)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
edoDistribStat< Distrib >* distrib_stat = new edoStatNormalMulti< EOT >();
|
||||
state.storeFunctor(distrib_stat);
|
||||
|
||||
|
|
@ -271,42 +158,24 @@ int main(int ac, char** av)
|
|||
file_monitor->add(*distrib_stat);
|
||||
distribution_continue->add( *file_monitor );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
eoPopLoopEval<EOT> popEval( eval );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// EDA algorithm configuration
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
edoAlgo< Distrib >* algo = new edoEDA< Distrib >
|
||||
(*selector, *estimator, *selectone, *modifier, *sampler,
|
||||
pop_continue, *distribution_continue,
|
||||
eval,
|
||||
//*sa_continue, *cooling_schedule, initial_temperature,
|
||||
*replacor);
|
||||
(*selector, *estimator, *sampler,
|
||||
pop_continue, *distribution_continue,
|
||||
popEval, *replacor);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Beginning of the algorithm call
|
||||
//-----------------------------------------------------------------------------
|
||||
try {
|
||||
do_run(*algo, pop);
|
||||
|
||||
try
|
||||
{
|
||||
do_run(*algo, pop);
|
||||
}
|
||||
catch (eoEvalFuncCounterBounderException& e)
|
||||
{
|
||||
eo::log << eo::warnings << "warning: " << e.what() << std::endl;
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
eo::log << eo::errors << "error: " << e.what() << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
} catch (eoEvalFuncCounterBounderException& e) {
|
||||
eo::log << eo::warnings << "warning: " << e.what() << std::endl;
|
||||
|
||||
} catch (std::exception& e) {
|
||||
eo::log << eo::errors << "error: " << e.what() << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue