Factorize algorithms code in a hierarchy of classes

CMAES-like algorithm (edoAlgoAdaptive) main loop work on an extern distribution passed as a reference, which is updated at each iteration
EDA-like algorithm (edoAlgoStateless) work on an intern distribution, that is replaced at each iteration

edoAlgoStateless inherits from edoAlgoAdaptive, and embed a default member on which the work is done.
This commit is contained in:
Johann Dreo 2012-07-18 10:41:17 +02:00
commit 8120116c1b
5 changed files with 136 additions and 80 deletions

View file

@ -140,7 +140,7 @@ int main(int ac, char** av)
eoPopLoopEval<RealVec> popEval( eval );
// EDA algorithm configuration
edoAlgo< Distrib >* algo = new edoAdaptiveAlgo< Distrib >
edoAlgo< Distrib >* algo = new edoAlgoAdaptive< Distrib >
(distribution, popEval, *selector, *estimator, *sampler, *replacor,
pop_continue, *distribution_continue );

View file

@ -161,7 +161,7 @@ int main(int ac, char** av)
eoPopLoopEval<EOT> popEval( eval );
// EDA algorithm configuration
edoAlgo< Distrib >* algo = new edoAdaptiveAlgo< Distrib >
edoAlgo< Distrib >* algo = new edoAlgoStateless< Distrib >
(popEval, *selector, *estimator, *sampler, *replacor,
pop_continue, *distribution_continue );

View file

@ -30,7 +30,8 @@ Authors:
#include "edoAlgo.h"
//#include "edoEDASA.h"
#include "edoAdaptiveAlgo.h"
#include "edoAlgoAdaptive.h"
#include "edoAlgoStateless.h"
#include "edoDistrib.h"
#include "edoUniform.h"

View file

@ -25,8 +25,8 @@ Authors:
Pierre Savéant <pierre.saveant@thalesgroup.com>
*/
#ifndef _edoAdaptiveAlgo_h
#define _edoAdaptiveAlgo_h
#ifndef _edoAlgoAdaptive_h
#define _edoAlgoAdaptive_h
#include <eo>
@ -43,7 +43,7 @@ Authors:
/** A generic stochastic search template for algorithms that need a distribution parameter.
*/
template < typename EOD >
class edoAdaptiveAlgo : public edoAlgo< EOD >
class edoAlgoAdaptive : public edoAlgo< EOD >
{
public:
//! Alias for the type EOT
@ -69,7 +69,7 @@ public:
\param pop_continuator Stopping criterion based on the population features
\param distribution_continuator Stopping criterion based on the distribution features
*/
edoAdaptiveAlgo(
edoAlgoAdaptive(
EOD & distrib,
eoPopEvalFunc < EOType > & evaluator,
eoSelect< EOType > & selector,
@ -79,7 +79,6 @@ public:
eoContinue< EOType > & pop_continuator,
edoContinue< EOD > & distribution_continuator
) :
_dummy_distrib(),
_distrib(distrib),
_evaluator(evaluator),
_selector(selector),
@ -91,38 +90,6 @@ public:
_distribution_continuator(distribution_continuator)
{}
/*!
Without a distribution
\param evaluation Evaluate a population
\param selector Selection of the best candidate solutions in the population
\param estimator Estimation of the distribution parameters
\param sampler Generate feasible solutions using the distribution
\param replacor Replace old solutions by new ones
\param pop_continuator Stopping criterion based on the population features
\param distribution_continuator Stopping criterion based on the distribution features
*/
edoAdaptiveAlgo(
eoPopEvalFunc < EOType > & evaluator,
eoSelect< EOType > & selector,
edoEstimator< EOD > & estimator,
edoSampler< EOD > & sampler,
eoReplacement< EOType > & replacor,
eoContinue< EOType > & pop_continuator,
edoContinue< EOD > & distribution_continuator
) :
_dummy_distrib(),
_distrib( _dummy_distrib ),
_evaluator(evaluator),
_selector(selector),
_estimator(estimator),
_sampler(sampler),
_replacor(replacor),
_pop_continuator(pop_continuator),
_dummy_continue(),
_distribution_continuator(distribution_continuator)
{}
//! constructor without an edoContinue
/*!
@ -136,7 +103,7 @@ public:
\param replacor Replace old solutions by new ones
\param pop_continuator Stopping criterion based on the population features
*/
edoAdaptiveAlgo (
edoAlgoAdaptive (
EOD & distrib,
eoPopEvalFunc < EOType > & evaluator,
eoSelect< EOType > & selector,
@ -145,7 +112,6 @@ public:
eoReplacement< EOType > & replacor,
eoContinue< EOType > & pop_continuator
) :
_dummy_distrib(),
_distrib( distrib ),
_evaluator(evaluator),
_selector(selector),
@ -157,36 +123,6 @@ public:
_distribution_continuator( _dummy_continue )
{}
//! constructor without an edoContinue nor a distribution
/*!
\param evaluation Evaluate a population
\param selector Selection of the best candidate solutions in the population
\param estimator Estimation of the distribution parameters
\param sampler Generate feasible solutions using the distribution
\param replacor Replace old solutions by new ones
\param pop_continuator Stopping criterion based on the population features
*/
edoAdaptiveAlgo (
eoPopEvalFunc < EOType > & evaluator,
eoSelect< EOType > & selector,
edoEstimator< EOD > & estimator,
edoSampler< EOD > & sampler,
eoReplacement< EOType > & replacor,
eoContinue< EOType > & pop_continuator
) :
_dummy_distrib(),
_distrib( _dummy_distrib ),
_evaluator(evaluator),
_selector(selector),
_estimator(estimator),
_sampler(sampler),
_replacor(replacor),
_pop_continuator(pop_continuator),
_dummy_continue(),
_distribution_continuator( _dummy_continue )
{}
/** Call the algorithm
*
* \param pop the population of candidate solutions
@ -235,13 +171,6 @@ public:
protected:
/** A dummy distribution, for algorithms willing to replace it instead of updating
*
* Thus we can instanciate _distrib on this and replace it at the first iteration with an estimator.
* This is why an edoDistrib must have an empty constructor.
*/
EOD _dummy_distrib;
//! The distribution that you want to update
EOD & _distrib;
@ -271,5 +200,5 @@ protected:
};
#endif // !_edoAdaptiveAlgo_h
#endif // !_edoAlgoAdaptive_h

126
edo/src/edoAlgoStateless.h Normal file
View file

@ -0,0 +1,126 @@
/*
The Evolving Distribution Objects framework (EDO) is a template-based,
ANSI-C++ evolutionary computation library which helps you to write your
own estimation of distribution algorithms.
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.1 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Copyright (C) 2010 Thales group
*/
/*
Authors:
Johann Dréo <johann.dreo@thalesgroup.com>
Pierre Savéant <pierre.saveant@thalesgroup.com>
*/
#ifndef _edoAlgoStateless_h
#define _edoAlgoStateless_h
#include "edoAlgoAdaptive.h"
//! edoEDA< D >
/** A generic stochastic search template for algorithms that need a distribution parameter.
*/
template < typename EOD >
class edoAlgoStateless : public edoAlgoAdaptive< EOD >
{
public:
//! Alias for the type EOT
typedef typename EOD::EOType EOType;
//! Alias for the atom type
typedef typename EOType::AtomType AtomType;
//! Alias for the fitness
typedef typename EOType::Fitness Fitness;
public:
/*!
Without a distribution
\param evaluation Evaluate a population
\param selector Selection of the best candidate solutions in the population
\param estimator Estimation of the distribution parameters
\param sampler Generate feasible solutions using the distribution
\param replacor Replace old solutions by new ones
\param pop_continuator Stopping criterion based on the population features
\param distribution_continuator Stopping criterion based on the distribution features
*/
edoAlgoStateless(
eoPopEvalFunc < EOType > & evaluator,
eoSelect< EOType > & selector,
edoEstimator< EOD > & estimator,
edoSampler< EOD > & sampler,
eoReplacement< EOType > & replacor,
eoContinue< EOType > & pop_continuator,
edoContinue< EOD > & distribution_continuator,
EOD* tmp_distrib = (new EOD())
) :
edoAlgoAdaptive<EOD>( *tmp_distrib, evaluator, selector, estimator, sampler, replacor, pop_continuator, distribution_continuator),
_tmp_distrib( tmp_distrib ),
_dummy_distrib()
{
this->_distrib = _dummy_distrib;
}
//! constructor without an edoContinue nor a distribution
/*!
\param evaluation Evaluate a population
\param selector Selection of the best candidate solutions in the population
\param estimator Estimation of the distribution parameters
\param sampler Generate feasible solutions using the distribution
\param replacor Replace old solutions by new ones
\param pop_continuator Stopping criterion based on the population features
*/
edoAlgoStateless (
eoPopEvalFunc < EOType > & evaluator,
eoSelect< EOType > & selector,
edoEstimator< EOD > & estimator,
edoSampler< EOD > & sampler,
eoReplacement< EOType > & replacor,
eoContinue< EOType > & pop_continuator,
EOD* tmp_distrib = (new EOD())
) :
edoAlgoAdaptive<EOD>( *tmp_distrib, evaluator, selector, estimator, sampler, replacor, pop_continuator),
_tmp_distrib( tmp_distrib ),
_dummy_distrib()
{
this->_distrib = _dummy_distrib;
}
~edoAlgoStateless()
{
delete _tmp_distrib;
}
protected:
EOD* _tmp_distrib;
/** A dummy distribution, for algorithms willing to replace it instead of updating
*
* Thus we can instanciate _distrib on this and replace it at the first iteration with an estimator.
* This is why an edoDistrib must have an empty constructor.
*/
EOD _dummy_distrib;
};
#endif // !_edoAlgoStateless_h