Skip to content

Commit

Permalink
fixed surrogate support for strategies with restart, ref CMA-ES#80
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Benazera committed Oct 25, 2014
1 parent 88c57a8 commit 49eb52b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions surrogatestrategy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ namespace libcmaes
template<template <class U,class V> class TStrategy, class TCovarianceUpdate, class TGenoPheno>
dMat ACMSurrogateStrategy<TStrategy,TCovarianceUpdate,TGenoPheno>::ask()
{
// when starting or restarting, make sure the training set is reset.
if (this->_niter == 0)
this->reset_training_set();

if (this->_exploit && (int)this->_tset.size() >= this->_l)
{
double lambda = eostrat<TGenoPheno>::_parameters._lambda; // XXX: hacky.
Expand Down
10 changes: 10 additions & 0 deletions surrogatestrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ namespace libcmaes
_auto_nsteps = true;
}

/**
* \brief resets training set and related information, useful when using algorithms with restarts
*/
inline void reset_training_set()
{
_tset.clear();
_train_err = _test_err = 0.0;
_smooth_test_err = 0.5;
}

/**
* \brief returns the current surrogate lifelength
* @return current surrogate lifelength
Expand Down

0 comments on commit 49eb52b

Please sign in to comment.