22#ifndef SURROGATESTRATEGY_H
23#define SURROGATESTRATEGY_H
25#include <libcmaes/eo_matrix.h>
26#include <libcmaes/cmastrategy.h>
38 typedef std::function<
int (
const std::vector<Candidate>&,
const dMat&)>
CSurrFunc;
46 typedef std::function<
int (std::vector<Candidate>&,
const dMat&)>
SurrFunc;
75 int train(
const std::vector<Candidate> &candidates,
76 const dMat &cov) {
return _train(candidates,cov); }
84 int predict(std::vector<Candidate> &candidates,
85 const dMat &cov) {
return _predict(candidates,cov); }
94 const dMat &cov=dMat(0,0));
238 void eval(
const dMat &candidates,
272 return ((this->_niter == 0 || this->_niter % this->
_nsteps == 0) && (
int)this->
_tset.size() >=
this->_l);
327 void eval(
const dMat &candidates,
362 return ((this->_niter == 0 || this->_niter % this->
_nsteps == 0) && (
int)this->
_tset.size() >=
this->_l);
425 std::random_device _rd;
426 std::normal_distribution<double> _norm_sel0;
427 std::normal_distribution<double> _norm_sel1;
ACM Surrogate strategy for CMA-ES, follows: 'Surrogate-Assisted Evolutionary Algorithms',...
Definition surrogatestrategy.h:295
void tell()
Updates the state of the stochastic search, and prepares for the next iteration by training the surro...
Definition surrogatestrategy.cc:275
int get_prelambda() const
returns the current number of pre-screened offpsrings (sampled)
Definition surrogatestrategy.h:391
double get_theta_sel1() const
returns the standard deviation of selection sampling step 0
Definition surrogatestrategy.h:415
bool do_train() const
whether to train the model
Definition surrogatestrategy.h:356
double _theta_sel0
Definition surrogatestrategy.h:419
void pre_selection_eval(const dMat &candidates)
pre-selection + candidate evaluation scheme. Called by eval, evaluates lambdaprime candidates with su...
Definition surrogatestrategy.cc:318
double _prelambda
Definition surrogatestrategy.h:418
void eval(const dMat &candidates, const dMat &phenocandidates=dMat(0, 0))
Evaluates a set of candiates against the objective function or the surrogate model,...
Definition surrogatestrategy.cc:247
int get_lambdaprime() const
returns the number of calls to the true objective function per iteration
Definition surrogatestrategy.h:379
void set_theta_sel1(const double &s)
sets the standard deviation of selection sampling step 1
Definition surrogatestrategy.h:409
void set_lambdaprime(const int &lp)
sets the number of true objective function calls per iteration
Definition surrogatestrategy.h:373
double get_theta_sel0() const
returns the standard deviation of selection sampling step 0
Definition surrogatestrategy.h:403
double _theta_sel1
Definition surrogatestrategy.h:420
void set_theta_sel0(const double &s)
sets the standard deviation of selection sampling step 0
Definition surrogatestrategy.h:397
int _lambdaprime
Definition surrogatestrategy.h:421
void set_prelambda(const int &pl)
sets the number of pre-screened offsprings (sampled)
Definition surrogatestrategy.h:385
dMat ask()
Generates a set of candidate points. Uses the pre-sampling of a larger than usual number of offprings...
Definition surrogatestrategy.cc:225
candidate solution point, in function parameter space.
Definition candidate.h:34
Covariance Matrix update. This is an implementation closely follows: Hansen, N. (2009)....
Definition covarianceupdate.h:38
an optimizer main class.
Definition esoptimizer.h:72
Simple surrogate strategy: trains every n steps, and exploits in between, mostly as an example and fo...
Definition surrogatestrategy.h:216
bool do_train() const
whether to train the model
Definition surrogatestrategy.h:268
int compute_lifelength()
estimates surrogate lifelength
Definition surrogatestrategy.cc:193
double _terr
Definition surrogatestrategy.h:276
void tell()
Updates the state of the stochastic search, and prepares for the next iteration by training the surro...
Definition surrogatestrategy.cc:172
int optimize()
Finds the minimum of the objective function. It makes alternate calls to ask(), tell() and stop() unt...
Definition surrogatestrategy.cc:185
void eval(const dMat &candidates, const dMat &phenocandidates=dMat(0, 0))
Evaluates a set of candiates against the objective function or the surrogate model,...
Definition surrogatestrategy.cc:128
Surrogate base class, to be derived in order to create strategy to be used along with CMA-ES.
Definition surrogatestrategy.h:55
int _auto_nsteps
Definition surrogatestrategy.h:206
void reset_training_set()
resets training set and related information, useful when using algorithms with restarts
Definition surrogatestrategy.h:182
int _l
Definition surrogatestrategy.h:197
bool _exploit
Definition surrogatestrategy.h:196
double _smooth_test_err
Definition surrogatestrategy.h:203
void set_train_error(const double &err)
sets training error
Definition surrogatestrategy.h:154
double _test_err
Definition surrogatestrategy.h:202
void set_fpredict(const SurrFunc &predict)
sets the prediction function
Definition surrogatestrategy.h:112
double compute_error(const std::vector< Candidate > &test_set, const dMat &cov=dMat(0, 0))
compute surrogate model error (copies and sorts the test_set)
Definition surrogatestrategy.cc:78
void set_nsteps(const int &nsteps)
sets the lifelength of the surrogate, i.e. the number of steps in between to training steps
Definition surrogatestrategy.h:172
int predict(std::vector< Candidate > &candidates, const dMat &cov)
predict from a surrogate model
Definition surrogatestrategy.h:84
void set_ftrain(const CSurrFunc &train)
sets the training function
Definition surrogatestrategy.h:106
void set_test_error(const double &err)
sets the test error and updates the smoothed test err.
Definition surrogatestrategy.cc:101
void set_l(const int &l)
sets the size of the training set (number of points)
Definition surrogatestrategy.h:118
std::vector< Candidate > _tset
Definition surrogatestrategy.h:198
double _train_err
Definition surrogatestrategy.h:201
void add_to_training_set(const Candidate &c)
adds a point to the training set (candidate = points + objective function value)
Definition surrogatestrategy.cc:70
int get_l() const
gets the size of the training set (number of points)
Definition surrogatestrategy.h:124
SurrFunc _predict
Definition surrogatestrategy.h:200
double _beta_err
Definition surrogatestrategy.h:204
int train(const std::vector< Candidate > &candidates, const dMat &cov)
train a surrogate model
Definition surrogatestrategy.h:75
int _nsteps
Definition surrogatestrategy.h:205
CSurrFunc _train
Definition surrogatestrategy.h:199
double get_test_error() const
returns the surrogate model test error
Definition surrogatestrategy.h:148
bool do_train() const
conditionals on training, to be specialized in inherited surrogate strategies
Definition surrogatestrategy.h:100
int get_nsteps() const
returns the current surrogate lifelength
Definition surrogatestrategy.h:193
double get_train_error() const
returns the surrogate model training error
Definition surrogatestrategy.h:142
bool get_exploit() const
gets the state of surrogate model exploitation
Definition surrogatestrategy.h:136
void set_exploit(const bool &exploit)
sets whether to exploit the surrogate model
Definition surrogatestrategy.h:130
linear scaling of the parameter space to achieve similar sensitivity across all components.
Definition acovarianceupdate.h:30
std::function< int(std::vector< Candidate > &, const dMat &)> SurrFunc
function to predict from a surrogate model
Definition surrogatestrategy.h:46
std::function< int(const std::vector< Candidate > &, const dMat &)> CSurrFunc
function to train a surrogate model
Definition surrogatestrategy.h:38