libcmaes 0.10.2
A C++11 library for stochastic optimization with CMA-ES
Loading...
Searching...
No Matches
libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria > Class Template Reference

Main class describing an evolutionary optimization strategy. Every algorithm in libcmaes descends from this class, and bring its functionalities to an ESOptimizer object. More...

#include <libcmaes/esostrategy.h>

Inheritance diagram for libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >:
libcmaes::CMAStrategy< TCovarianceUpdate, TGenoPheno >

Public Member Functions

 ESOStrategy ()
 dummy constructor.
 
 ESOStrategy (FitFunc &func, TParameters &parameters)
 constructor
 
 ESOStrategy (FitFunc &func, TParameters &parameters, const TSolutions &solutions)
 constructor for starting from an existing solution.
 
dMat ask ()
 Generates a set of candidate points.
 
void eval (const dMat &candidates, const dMat &phenocandidates=dMat(0, 0))
 Evaluates a set of candidates against the objective function. The procedure is multithreaded and stores both the candidates and their f-value into the _solutions object that bears the current set of potential solutions to the optimization problem.
 
void tell ()
 Updates the state of the stochastic search, and prepares for the next iteration.
 
bool stop ()
 Decides whether to stop the search for solutions.
 
int optimize (const EvalFunc &evalf, const AskFunc &askf, const TellFunc &tellf)
 Finds the minimum of the objective function. It makes alternative calls to ask(), tell() and stop() until one of the termination criteria triggers.
 
void inc_iter ()
 increment iteration count.
 
void update_fevals (const int &evals)
 updates the consumed budget of objective function evaluations.
 
void set_gradient_func (GradFunc &gfunc)
 sets the gradient function, if available.
 
void set_progress_func (ProgressFunc< TParameters, TSolutions > &pfunc)
 Sets the possibly custom progress function, that is called in between every search step, and gives an outside user a simple way to witness progress of the algorithm, as well as to add custom termination criteria.
 
void start_from_solution (const TSolutions &sol)
 starts optimization from a given solution object.
 
void set_plot_func (PlotFunc< TParameters, TSolutions > &pffunc)
 Sets the possibly custom plot to file function, that is useful for storing into file various possibly custom variable values for each step until termination.
 
dVec gradf (const dVec &x)
 returns numerical gradient of objective function at x.
 
dVec gradgp (const dVec &x) const
 returns the numerical gradient of the objective function in phenotype space
 
double edm ()
 computes expected distance to minimum (EDM).
 
TSolutionsget_solutions ()
 returns reference to current solution object
 
TParametersget_parameters ()
 returns reference to current optimization parameters object
 
double fitfunc (const double *x, const int N)
 execute objective function
 
void uncertainty_handling ()
 uncertainty handling scheme that computes and uncertainty level based on a dual candidate ranking.
 
void perform_uh (const dMat &candidates, const dMat &phenocandidates, int &nfcalls)
 uncertainty handling scheme that perform completely the reevaluation of solutions.
 
void select_candidates_uh (const dMat &candidates, const dMat &phenocandidates, dMat &candidates_uh)
 part of the ucertainty handling scheme that select which candidates should be reevaluated.
 
void eval_candidates_uh (const dMat &candidates, const dMat &candidates_uh, std::vector< RankedCandidate > &nvcandidates, int &nfcalls)
 part of the ucertainty handling scheme that evaluate the candidates to be reevaluated.
 
void set_candidates_uh (const std::vector< RankedCandidate > &nvcandidates)
 part of the ucertainty handling scheme that set the results of evaluation to the solutions.
 
void tpa_update ()
 updates the two-point adaptation average rank difference for the step-size adaptation mechanism
 
Candidate best_solution () const
 
void set_initial_elitist (const bool &e)
 

Protected Attributes

FitFunc _func
 
int _nevals
 
int _niter
 
TSolutions _solutions
 
TParameters _parameters
 
ProgressFunc< TParameters, TSolutions_pfunc
 
GradFunc _gfunc = nullptr
 
PlotFunc< TParameters, TSolutions_pffunc
 
FitFunc _funcaux
 
bool _initial_elitist = false
 

Private Attributes

std::mt19937 _uhgen
 
std::uniform_real_distribution _uhunif
 
Eigen::EigenMultivariateNormal< double_uhesolver
 

Detailed Description

template<class TParameters, class TSolutions, class TStopCriteria>
class libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >

Main class describing an evolutionary optimization strategy. Every algorithm in libcmaes descends from this class, and bring its functionalities to an ESOptimizer object.

Constructor & Destructor Documentation

◆ ESOStrategy() [1/2]

libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::ESOStrategy ( FitFunc &  func,
TParameters parameters 
)

constructor

Parameters
funcfunction to minimize
parametersoptimization parameters

◆ ESOStrategy() [2/2]

libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::ESOStrategy ( FitFunc &  func,
TParameters parameters,
const TSolutions solutions 
)

constructor for starting from an existing solution.

Parameters
funcobjective function to minimize
parametersstochastic search parameters
solutionsolution object to start from

Member Function Documentation

◆ ask()

Generates a set of candidate points.

Returns
A matrix whose rows contain the candidate points.

◆ edm()

computes expected distance to minimum (EDM).

Returns
EDM

◆ eval()

void libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::eval ( const dMat &  candidates,
const dMat &  phenocandidates = dMat(0,0) 
)

Evaluates a set of candidates against the objective function. The procedure is multithreaded and stores both the candidates and their f-value into the _solutions object that bears the current set of potential solutions to the optimization problem.

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

◆ fitfunc()

execute objective function

Parameters
xpoint at which to execute the function
Ndimension of array x
Returns
objective function value at x

◆ get_parameters()

returns reference to current optimization parameters object

Returns
current optimization parameters object

◆ get_solutions()

returns reference to current solution object

Returns
current solution object

◆ gradf()

returns numerical gradient of objective function at x.

Parameters
xpoint at which to compute the gradient
Returns
vector of numerical gradient of the objective function at x.

◆ gradgp()

returns the numerical gradient of the objective function in phenotype space

Parameters
xpoint in genotype coordinates at which to compute the gradient
Returns
vector of numerical gradient computed in phenotype space

◆ optimize()

int libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::optimize ( const EvalFunc &  evalf,
const AskFunc &  askf,
const TellFunc &  tellf 
)

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

Parameters
evalfcustom eval function
askfcustom ask function
tellfcustom tell function
Returns
success or error code, as defined in opti_err.h

◆ set_gradient_func()

void libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::set_gradient_func ( GradFunc &  gfunc)
inline

sets the gradient function, if available.

Parameters
gfuncgradient function

◆ set_plot_func()

Sets the possibly custom plot to file function, that is useful for storing into file various possibly custom variable values for each step until termination.

Parameters
pffunca stream to file output function

◆ set_progress_func()

void libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::set_progress_func ( ProgressFunc< TParameters, TSolutions > &  pfunc)
inline

Sets the possibly custom progress function, that is called in between every search step, and gives an outside user a simple way to witness progress of the algorithm, as well as to add custom termination criteria.

Parameters
pfunca progress function

◆ start_from_solution()

starts optimization from a given solution object.

Parameters
solthe solution object to start search from.

◆ stop()

Decides whether to stop the search for solutions.

Returns
true if search must stop, false otherwise.

◆ update_fevals()

updates the consumed budget of objective function evaluations.

Parameters
evalsincrement to the current consumed budget

Member Data Documentation

◆ _func

the objective function.

◆ _gfunc

gradient function, when available.

◆ _initial_elitist

restarts from and re-injects best seen solution if not the final one.

◆ _nevals

number of function evaluations.

◆ _niter

number of iterations.

◆ _parameters

the optimizer's set of static parameters, from inputs or internal.

◆ _pffunc

possibly custom stream data to file function.

◆ _pfunc

possibly custom progress function.

◆ _solutions

holder of the current set of solutions and the dynamic elemenst of the search state in general.

◆ _uhgen

random device used for uncertainty handling operations.


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