libcmaes 0.10.2
A C++11 library for stochastic optimization with CMA-ES
|
Surrogate base class, to be derived in order to create strategy to be used along with CMA-ES. More...
#include <libcmaes/surrogatestrategy.h>
Public Member Functions | |
SurrogateStrategy (FitFunc &func, CMAParameters< TGenoPheno > ¶meters) | |
constructor | |
int | train (const std::vector< Candidate > &candidates, const dMat &cov) |
train a surrogate model | |
int | predict (std::vector< Candidate > &candidates, const dMat &cov) |
predict from a surrogate model | |
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) | |
bool | do_train () const |
conditionals on training, to be specialized in inherited surrogate strategies | |
void | set_ftrain (const CSurrFunc &train) |
sets the training function | |
void | set_fpredict (const SurrFunc &predict) |
sets the prediction function | |
void | set_l (const int &l) |
sets the size of the training set (number of points) | |
int | get_l () const |
gets the size of the training set (number of points) | |
void | set_exploit (const bool &exploit) |
sets whether to exploit the surrogate model | |
bool | get_exploit () const |
gets the state of surrogate model exploitation | |
double | get_train_error () const |
returns the surrogate model training error | |
double | get_test_error () const |
returns the surrogate model test error | |
void | set_train_error (const double &err) |
sets training error | |
void | set_test_error (const double &err) |
sets the test error and updates the smoothed test err. | |
void | add_to_training_set (const Candidate &c) |
adds a point to the training set (candidate = points + objective function value) | |
void | set_nsteps (const int &nsteps) |
sets the lifelength of the surrogate, i.e. the number of steps in between to training steps | |
void | reset_training_set () |
resets training set and related information, useful when using algorithms with restarts | |
int | get_nsteps () const |
returns the current surrogate lifelength | |
Protected Attributes | |
bool | _exploit = true |
int | _l = 200 |
std::vector< Candidate > | _tset |
CSurrFunc | _train |
SurrFunc | _predict |
double | _train_err = 0.0 |
double | _test_err = 0.0 |
double | _smooth_test_err = 0.5 |
double | _beta_err = 0.2 |
int | _nsteps = 1 |
int | _auto_nsteps = false |
Surrogate base class, to be derived in order to create strategy to be used along with CMA-ES.
libcmaes::SurrogateStrategy< TStrategy, TCovarianceUpdate, TGenoPheno >::SurrogateStrategy | ( | FitFunc & | func, |
CMAParameters< TGenoPheno > & | parameters | ||
) |
constructor
func | objective function to minimize |
parameters | optimization parameters |
void libcmaes::SurrogateStrategy< TStrategy, TCovarianceUpdate, TGenoPheno >::add_to_training_set | ( | const Candidate & | c | ) |
adds a point to the training set (candidate = points + objective function value)
c | point to add to the training set |
double libcmaes::SurrogateStrategy< TStrategy, TCovarianceUpdate, TGenoPheno >::compute_error | ( | const std::vector< Candidate > & | test_set, |
const dMat & | cov = dMat(0,0) |
||
) |
compute surrogate model error (copies and sorts the test_set)
test_set | the candidate points along with their objective function values for model evaluation |
cov | possibly empty covariance matrix in order to re-scale the points before error estimation |
|
inline |
conditionals on training, to be specialized in inherited surrogate strategies
|
inline |
gets the state of surrogate model exploitation
|
inline |
gets the size of the training set (number of points)
|
inline |
returns the current surrogate lifelength
|
inline |
returns the surrogate model test error
|
inline |
returns the surrogate model training error
|
inline |
predict from a surrogate model
candidates | set of points for which value is to be predicted |
cov | a possibly empty covariance matrix in order to re-scale points before predicting |
|
inline |
sets whether to exploit the surrogate model
exploit | whether to exploit the surrogate model |
|
inline |
sets the prediction function
prediction | function |
|
inline |
sets the training function
training | function |
|
inline |
sets the size of the training set (number of points)
l | size of the training set |
|
inline |
sets the lifelength of the surrogate, i.e. the number of steps in between to training steps
nsteps | surrogate lifelength, -1 for automatic determination |
void libcmaes::SurrogateStrategy< TStrategy, TCovarianceUpdate, TGenoPheno >::set_test_error | ( | const double & | err | ) |
sets the test error and updates the smoothed test err.
err | test error |
|
inline |
sets training error
err | training error |
|
inline |
train a surrogate model
candidates | set of points along with objective function value |
cov | a possibly empty covariance matrix in order to re-scale points before training |
|
protected |
whether to automatically set the surrogate lifelength.
|
protected |
smoothing constant.
|
protected |
whether to exploit or test the surrogate.
|
protected |
number of training samples. set to floor(30*sqrt(n)) in constructor.
|
protected |
steps in between two training phases.
|
protected |
custom prediction function.
|
protected |
smoothed test error as (1-\beta_err)*_test_err + \beta_err * new_test_err
|
protected |
current surrogate model error estimate.
|
protected |
custom training function.
|
protected |
current surrogate training error.
|
protected |
current training set.