libcmaes 0.10.2
A C++11 library for stochastic optimization with CMA-ES
Loading...
Searching...
No Matches
libcmaes::SimpleSurrogateStrategy< TStrategy, TCovarianceUpdate, TGenoPheno > Class Template Reference

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>

Inheritance diagram for libcmaes::SimpleSurrogateStrategy< TStrategy, TCovarianceUpdate, TGenoPheno >:
libcmaes::SurrogateStrategy< TStrategy, TCovarianceUpdate, TGenoPheno >

Public Member Functions

 SimpleSurrogateStrategy (FitFunc &func, CMAParameters< TGenoPheno > &parameters)
 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 > &parameters)
 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
 

Detailed Description

template<template< class U, class V > class TStrategy, class TCovarianceUpdate = CovarianceUpdate, class TGenoPheno = GenoPheno<NoBoundStrategy>>
class libcmaes::SimpleSurrogateStrategy< TStrategy, TCovarianceUpdate, TGenoPheno >

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.

Constructor & Destructor Documentation

◆ SimpleSurrogateStrategy()

libcmaes::SimpleSurrogateStrategy< TStrategy, TCovarianceUpdate, TGenoPheno >::SimpleSurrogateStrategy ( FitFunc &  func,
CMAParameters< TGenoPheno > &  parameters 
)

constructor

Parameters
funcobjective function to minimize
parametersoptimization parameters

Member Function Documentation

◆ compute_lifelength()

estimates surrogate lifelength

Returns
estimated surrogate lifelength

◆ do_train()

template<template< class U, class V > class TStrategy, class TCovarianceUpdate = CovarianceUpdate, class TGenoPheno = GenoPheno<NoBoundStrategy>>
bool libcmaes::SimpleSurrogateStrategy< TStrategy, TCovarianceUpdate, TGenoPheno >::do_train ( ) const
inline

whether to train the model

Returns
whether to train the model

◆ eval()

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

Parameters
candidatesA matrix whose rows contain the candidates.
phenocandidatesThe candidates transformed into phenotype, leave empty if no pheno transform.

◆ optimize()

Finds the minimum of the objective function. It makes alternate calls to ask(), tell() and stop() until one of the termination criteria triggers.

Returns
success or error code, as defined in opti_err.h Note: the termination criteria code is held by _solutions._run_status

◆ 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

Member Data Documentation

◆ _terr

template<template< class U, class V > class TStrategy, class TCovarianceUpdate = CovarianceUpdate, class TGenoPheno = GenoPheno<NoBoundStrategy>>
double libcmaes::SimpleSurrogateStrategy< TStrategy, TCovarianceUpdate, TGenoPheno >::_terr = 0.45

error threshold for estimating optimal nsteps


The documentation for this class was generated from the following files: