libcmaes
A C++11 library for stochastic optimization with CMA-ES
 All Classes Namespaces Functions Variables Typedefs
Public Member Functions | Protected Attributes | List of all members
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 <esostrategy.h>

Public Member Functions

 ESOStrategy ()
 dummy constructor.
 
 ESOStrategy (FitFunc &func, TParameters &parameters)
 constructor More...
 
 ESOStrategy (FitFunc &func, TParameters &parameters, const TSolutions &solutions)
 constructor for starting from an existing solution. More...
 
dMat ask ()
 Generates a set of candidate points. More...
 
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. More...
 
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. More...
 
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. More...
 
void inc_iter ()
 increment iteration count.
 
void update_fevals (const int &evals)
 updates the consumed budget of objective function evaluations. More...
 
void set_gradient_func (GradFunc &gfunc)
 sets the gradient function, if available. More...
 
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. More...
 
void start_from_solution (const TSolutions &sol)
 starts optimization from a given solution object. More...
 
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. More...
 
dVec gradf (const dVec &x)
 returns numerical gradient of objective function at x. More...
 
dVec gradgp (const dVec &x) const
 returns the numerical gradient of the objective function in phenotype space More...
 
double edm ()
 computes expected distance to minimum (EDM). More...
 
TSolutions & get_solutions ()
 returns reference to current solution object More...
 
TParameters & get_parameters ()
 returns reference to current optimization parameters object More...
 
double fitfunc (const double *x, const int N)
 execute objective function More...
 
void uncertainty_handling ()
 uncertainty handling scheme that computes and uncertainty level based on a dual candidate ranking.
 
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
 

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

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

constructor

Parameters
funcfunction to minimize
parametersoptimization parameters
template<class TParameters, class TSolutions, class TStopCriteria >
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

template<class TParameters, class TSolutions, class TStopCriteria>
dMat libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::ask ( )

Generates a set of candidate points.

Returns
A matrix whose rows contain the candidate points.
template<class TParameters , class TSolutions , class TStopCriteria >
double libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::edm ( )

computes expected distance to minimum (EDM).

Returns
EDM
template<class TParameters , class TSolutions , class TStopCriteria >
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.
template<class TParameters, class TSolutions, class TStopCriteria>
double libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::fitfunc ( const double *  x,
const int  N 
)
inline

execute objective function

Parameters
xpoint at which to execute the function
Ndimension of array x
Returns
objective function value at x
template<class TParameters, class TSolutions, class TStopCriteria>
TParameters& libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::get_parameters ( )
inline

returns reference to current optimization parameters object

Returns
current optimization parameters object
template<class TParameters, class TSolutions, class TStopCriteria>
TSolutions& libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::get_solutions ( )
inline

returns reference to current solution object

Returns
current solution object
template<class TParameters , class TSolutions , class TStopCriteria >
dVec libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::gradf ( const dVec &  x)

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.
template<class TParameters , class TSolutions , class TStopCriteria >
dVec libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::gradgp ( const dVec &  x) const

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
template<class TParameters, class TSolutions, class TStopCriteria>
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
template<class TParameters, class TSolutions, class TStopCriteria>
void libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::set_gradient_func ( GradFunc &  gfunc)
inline

sets the gradient function, if available.

Parameters
gfuncgradient function
template<class TParameters, class TSolutions, class TStopCriteria>
void libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::set_plot_func ( PlotFunc< TParameters, TSolutions > &  pffunc)
inline

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
template<class TParameters, class TSolutions, class TStopCriteria>
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
template<class TParameters, class TSolutions, class TStopCriteria>
void libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::start_from_solution ( const TSolutions &  sol)
inline

starts optimization from a given solution object.

Parameters
solthe solution object to start search from.
template<class TParameters, class TSolutions, class TStopCriteria>
bool libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::stop ( )

Decides whether to stop the search for solutions.

Returns
true if search must stop, false otherwise.
template<class TParameters , class TSolutions , class TStopCriteria >
void libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::update_fevals ( const int &  evals)

updates the consumed budget of objective function evaluations.

Parameters
evalsincrement to the current consumed budget

Member Data Documentation

template<class TParameters, class TSolutions, class TStopCriteria>
FitFunc libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::_func
protected

the objective function.

template<class TParameters, class TSolutions, class TStopCriteria>
GradFunc libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::_gfunc = nullptr
protected

gradient function, when available.

template<class TParameters, class TSolutions, class TStopCriteria>
bool libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::_initial_elitist = false
protected

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

template<class TParameters, class TSolutions, class TStopCriteria>
int libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::_nevals
protected

number of function evaluations.

template<class TParameters, class TSolutions, class TStopCriteria>
int libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::_niter
protected

number of iterations.

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

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

template<class TParameters, class TSolutions, class TStopCriteria>
PlotFunc<TParameters,TSolutions> libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::_pffunc
protected

possibly custom stream data to file function.

template<class TParameters, class TSolutions, class TStopCriteria>
ProgressFunc<TParameters,TSolutions> libcmaes::ESOStrategy< TParameters, TSolutions, TStopCriteria >::_pfunc
protected

possibly custom progress function.

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

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


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