libcmaes
A C++11 library for stochastic optimization with CMA-ES
 All Classes Namespaces Functions Variables Typedefs
cmastrategy.h
1 
22 #ifndef CMASTRATEGY_H
23 #define CMASTRATEGY_H
24 
25 #include "esostrategy.h"
26 #include "cmaparameters.h"
27 #include "cmasolutions.h"
28 #include "cmastopcriteria.h"
29 #include "covarianceupdate.h"
30 #include "acovarianceupdate.h"
31 #include "vdcmaupdate.h"
32 #include "eigenmvn.h"
33 #include <fstream>
34 
35 namespace libcmaes
36 {
37 
44  template <class TCovarianceUpdate,class TGenoPheno=GenoPheno<NoBoundStrategy>>
45  class CMAStrategy : public ESOStrategy<CMAParameters<TGenoPheno>,CMASolutions,CMAStopCriteria<TGenoPheno> >
46  {
47  public:
51  CMAStrategy();
52 
58  CMAStrategy(FitFunc &func,
59  CMAParameters<TGenoPheno> &parameters);
60 
67  CMAStrategy(FitFunc &func,
68  CMAParameters<TGenoPheno> &parameters,
69  const CMASolutions &cmasols);
70 
71  ~CMAStrategy();
72 
78  dMat ask();
79 
83  void tell();
84 
89  bool stop();
90 
101  int optimize(const EvalFunc &evalf, const AskFunc &askf, const TellFunc &tellf);
102 
110  int optimize()
111  {
112  return optimize(std::bind(&ESOStrategy<CMAParameters<TGenoPheno>,CMASolutions,CMAStopCriteria<TGenoPheno>>::eval,this,std::placeholders::_1,std::placeholders::_2),
115  }
116 
121  void plot();
122 
123  protected:
126  std::ofstream *_fplotstream = nullptr;
128  public:
129  static ProgressFunc<CMAParameters<TGenoPheno>,CMASolutions> _defaultPFunc;
130  static PlotFunc<CMAParameters<TGenoPheno>,CMASolutions> _defaultFPFunc;
131  };
132 
133 }
134 
135 #endif
dMat ask()
generates nsols new candidate solutions, sampled from a multivariate normal distribution. return A matrix whose rows contain the candidate points.
Definition: cmastrategy.cc:147
Holder of the set of evolving solutions from running an instance of CMA-ES.
Definition: cmasolutions.h:41
void plot()
Stream the internal state of the search into an output file, as defined in the _parameters object...
Definition: cmastrategy.cc:392
Main class describing an evolutionary optimization strategy. Every algorithm in libcmaes descends fro...
Definition: esostrategy.h:51
static PlotFunc< CMAParameters< TGenoPheno >, CMASolutions > _defaultFPFunc
Definition: cmastrategy.h:130
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 stor...
int optimize()
Finds the minimum of the objective function. It makes alternate calls to ask(), tell() and stop() unt...
Definition: cmastrategy.h:110
linear scaling of the parameter space to achieve similar sensitivity across all components.
Definition: acovarianceupdate.cc:25
Parameters for various flavors of the CMA-ES algorithm.
Definition: cmaparameters.h:35
CMA-ES termination criteria, see reference paper in cmastrategy.h.
Definition: cmastopcriteria.h:75
CMAStrategy()
dummy constructor
Definition: cmastrategy.cc:94
std::ofstream * _fplotstream
Definition: cmastrategy.h:126
bool stop()
Stops search on a set of termination criterias, see reference paper.
Definition: cmastrategy.cc:315
This is an implementation of CMA-ES. It uses the reference algorithm and termination criteria of the ...
Definition: cmastrategy.h:45
Eigen::EigenMultivariateNormal< double > _esolver
Definition: cmastrategy.h:124
CMAStopCriteria< TGenoPheno > _stopcriteria
Definition: cmastrategy.h:125
void tell()
Updates the covariance matrix and prepares for the next iteration.
Definition: cmastrategy.cc:273
static ProgressFunc< CMAParameters< TGenoPheno >, CMASolutions > _defaultPFunc
Definition: cmastrategy.h:129