|
libcmaes 0.10.2
A C++11 library for stochastic optimization with CMA-ES
|
Simple surrogate strategy: trains every n steps, and exploits in between, mostly as an example and for testing / debugging surrogates. This strategy overrides the ask/eval/tell functions of the base optimization strategy. More...
#include <libcmaes/surrogatestrategy.h>
Public Member Functions | |
| SimpleSurrogateStrategy (FitFunc &func, CMAParameters< TGenoPheno > ¶meters) | |
| constructor | |
| void | eval (const dMat &candidates, const dMat &phenocandidates=dMat(0, 0)) |
| Evaluates a set of candiates against the objective function or the surrogate model, as needed. | |
| void | tell () |
| Updates the state of the stochastic search, and prepares for the next iteration by training the surrogate model, as needed. | |
| int | optimize () |
| Finds the minimum of the objective function. It makes alternate calls to ask(), tell() and stop() until one of the termination criteria triggers. | |
| int | compute_lifelength () |
| estimates surrogate lifelength | |
| bool | do_train () const |
| whether to train the model | |
Public Member Functions inherited from libcmaes::SurrogateStrategy< TStrategy, TCovarianceUpdate, TGenoPheno > | |
| 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 | |
Public Attributes | |
| double | _terr = 0.45 |
| int | _nmax = 20 |
Additional Inherited Members | |
Protected Attributes inherited from libcmaes::SurrogateStrategy< TStrategy, TCovarianceUpdate, TGenoPheno > | |
| 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 |
Simple surrogate strategy: trains every n steps, and exploits in between, mostly as an example and for testing / debugging surrogates. This strategy overrides the ask/eval/tell functions of the base optimization strategy.
| libcmaes::SimpleSurrogateStrategy< TStrategy, TCovarianceUpdate, TGenoPheno >::SimpleSurrogateStrategy | ( | FitFunc & | func, |
| CMAParameters< TGenoPheno > & | parameters | ||
| ) |
constructor
| func | objective function to minimize |
| parameters | optimization parameters |
| int libcmaes::SimpleSurrogateStrategy< TStrategy, TCovarianceUpdate, TGenoPheno >::compute_lifelength | ( | ) |
estimates surrogate lifelength
|
inline |
whether to train the model
| void libcmaes::SimpleSurrogateStrategy< TStrategy, TCovarianceUpdate, TGenoPheno >::eval | ( | const dMat & | candidates, |
| const dMat & | phenocandidates = dMat(0,0) |
||
| ) |
Evaluates a set of candiates against the objective function or the surrogate model, as needed.
Note: this function overrides the default CMAStrategy::eval
| candidates | A matrix whose rows contain the candidates. |
| phenocandidates | The candidates transformed into phenotype, leave empty if no pheno transform. |
| int libcmaes::SimpleSurrogateStrategy< TStrategy, TCovarianceUpdate, TGenoPheno >::optimize | ( | ) |
Finds the minimum of the objective function. It makes alternate calls to ask(), tell() and stop() until one of the termination criteria triggers.
| void libcmaes::SimpleSurrogateStrategy< TStrategy, TCovarianceUpdate, TGenoPheno >::tell | ( | ) |
Updates the state of the stochastic search, and prepares for the next iteration by training the surrogate model, as needed.
Note: this function overrides the default CMAStrategy::tell
| double libcmaes::SimpleSurrogateStrategy< TStrategy, TCovarianceUpdate, TGenoPheno >::_terr = 0.45 |
error threshold for estimating optimal nsteps