Skip to content

Commit

Permalink
cleanup of generic strategy reuse scheme, ref #80 #81
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Benazera committed Oct 27, 2014
1 parent 71dc458 commit 305cf97
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 9 deletions.
11 changes: 11 additions & 0 deletions src/bipopcmastrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ namespace libcmaes
* Note: the termination criteria code is held by _solutions._run_status
*/
int optimize(const EvalFunc &evalf,const AskFunc &askf,const TellFunc &tellf);

/**
* \brief Finds the minimum of the objective function. It makes
* alternate calls to ask(), tell() and stop() until
* one of the termination criteria triggers.
* @param evalf custom eval function
* @param askf custom ask function
* @param tellf custom tell function
* @return success or error code, as defined in opti_err.h
* Note: the termination criteria code is held by _solutions._run_status
*/
int optimize()
{
return optimize(std::bind(&BIPOPCMAStrategy<TCovarianceUpdate,TGenoPheno>::eval,this,std::placeholders::_1,std::placeholders::_2),
Expand Down
17 changes: 11 additions & 6 deletions src/cmastrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,24 @@ namespace libcmaes
* \brief Finds the minimum of the objective function. It makes
* alternate calls to ask(), tell() and stop() until
* one of the termination criteria triggers.
* @param evalf custom eval function
* @param askf custom ask function
* @param tellf custom tell function
* @return success or error code, as defined in opti_err.h
* Note: the termination criteria code is held by _solutions._run_status
*/
void eval(const dMat &candidates,
const dMat &phenocandidates=dMat(0,0))
{
ESOStrategy<CMAParameters<TGenoPheno>,CMASolutions,CMAStopCriteria<TGenoPheno>>::eval(candidates,phenocandidates);
}
int optimize(const EvalFunc &evalf, const AskFunc &askf, const TellFunc &tellf);

/**
* \brief Finds the minimum of the objective function. It makes
* alternate calls to ask(), tell() and stop() until
* one of the termination criteria triggers.
* @return success or error code, as defined in opti_err.h
* Note: the termination criteria code is held by _solutions._run_status
*/
int optimize()
{
return optimize(std::bind(&ESOStrategy<CMAParameters<TGenoPheno>,CMASolutions,CMAStopCriteria<TGenoPheno>>::eval,this,std::placeholders::_1,std::placeholders::_2),
/*std::bind(&CMAStrategy<TCovarianceUpdate,TGenoPheno>::eval,this,std::placeholders::_1,std::placeholders::_2),*/
std::bind(&CMAStrategy<TCovarianceUpdate,TGenoPheno>::ask,this),
std::bind(&CMAStrategy<TCovarianceUpdate,TGenoPheno>::tell,this));
}
Expand Down
4 changes: 3 additions & 1 deletion src/esostrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ namespace libcmaes
* \brief Finds the minimum of the objective function. It makes
* alternative calls to ask(), tell() and stop() until
* one of the termination criteria triggers.
* @param evalf custom eval function
* @param askf custom ask function
* @param tellf custom tell function
* @return success or error code, as defined in opti_err.h
*/
//int optimize(ESOStrategy<TParameters,TSolutions,TStopCriteria> &strat);
int optimize(const EvalFunc &evalf, const AskFunc &askf, const TellFunc &tellf);

/**
Expand Down
11 changes: 11 additions & 0 deletions src/ipopcmastrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,21 @@ namespace libcmaes
* \brief Finds the minimum of the objective function. It makes
* alternate calls to ask(), tell() and stop() until
* one of the termination criteria triggers.
* @param evalf custom eval function
* @param askf custom ask function
* @param tellf custom tell function
* @return success or error code, as defined in opti_err.h
* Note: the termination criteria code is held by _solutions._run_status
*/
int optimize(const EvalFunc &evalf, const AskFunc &askf,const TellFunc &tellf);

/**
* \brief Finds the minimum of the objective function. It makes
* alternate calls to ask(), tell() and stop() until
* one of the termination criteria triggers.
* @return success or error code, as defined in opti_err.h
* Note: the termination criteria code is held by _solutions._run_status
*/
int optimize()
{
return optimize(std::bind(&IPOPCMAStrategy<TCovarianceUpdate,TGenoPheno>::eval,this,std::placeholders::_1,std::placeholders::_2),
Expand Down
3 changes: 1 addition & 2 deletions src/surrogatestrategy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace libcmaes
{
eostrat<TGenoPheno>::_pfunc = [this](const CMAParameters<TGenoPheno> &cmaparams, const CMASolutions &cmasols)
{
LOG_IF(INFO,!cmaparams.quiet()) << "iter=" << cmasols.niter() << " / evals=" << cmasols.fevals() << " / f-value=" << cmasols.best_candidate().get_fvalue() << " / sigma=" << cmasols.sigma() << " / trainerr=" << this->_train_err << " / testerr=" << this->_test_err << " / smtesterr=" << this->_smooth_test_err << " / slifel=" << this->_nsteps << std::endl;//compute_lifelength() << std::endl;
LOG_IF(INFO,!cmaparams.quiet()) << "iter=" << cmasols.niter() << " / evals=" << cmasols.fevals() << " / f-value=" << cmasols.best_candidate().get_fvalue() << " / sigma=" << cmasols.sigma() << " / trainerr=" << this->_train_err << " / testerr=" << this->_test_err << " / smtesterr=" << this->_smooth_test_err << " / slifel=" << this->_nsteps << std::endl;
return 0;
};
this->_stopcriteria.set_criteria_active(STAGNATION,false); // deactivate stagnation check due to the presence of ranks as median objective function values
Expand Down Expand Up @@ -180,7 +180,6 @@ namespace libcmaes
return TStrategy<TCovarianceUpdate,TGenoPheno>::optimize(std::bind(&SimpleSurrogateStrategy<TStrategy,TCovarianceUpdate,TGenoPheno>::eval,this,std::placeholders::_1,std::placeholders::_2),
std::bind(&CMAStrategy<TCovarianceUpdate,TGenoPheno>::ask,this),
std::bind(&SimpleSurrogateStrategy<TStrategy,TCovarianceUpdate,TGenoPheno>::tell,this));
//return TStrategy<TCovarianceUpdate,TGenoPheno>::template optimize<SimpleSurrogateStrategy>(*this);
}

template<template <class U,class V> class TStrategy, class TCovarianceUpdate, class TGenoPheno>
Expand Down
7 changes: 7 additions & 0 deletions src/surrogatestrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ namespace libcmaes
*/
void tell();

/**
* \brief Finds the minimum of the objective function. It makes
* alternate calls to ask(), tell() and stop() until
* one of the termination criteria triggers.
* @return success or error code, as defined in opti_err.h
* Note: the termination criteria code is held by _solutions._run_status
*/
int optimize();

/**
Expand Down

0 comments on commit 305cf97

Please sign in to comment.