libcmaes 0.10.3
A C++11 library for stochastic optimization with CMA-ES
Loading...
Searching...
No Matches
cmaparameters.h
1
22#ifndef CMAPARAMETERS_H
23#define CMAPARAMETERS_H
24
25#include <libcmaes/parameters.h>
26#include <libcmaes/eo_matrix.h>
27#include <libcmaes/cmaes_export.h>
28#include <float.h>
29
30namespace libcmaes
31{
35 template <class TGenoPheno=GenoPheno<NoBoundStrategy> >
36 class CMAES_EXPORT CMAParameters : public Parameters<TGenoPheno>
37 {
38 friend class CMASolutions;
39 template <class U, class V> friend class CMAStrategy;
40 template <class U, class V, class W> friend class ESOStrategy;
41 template <class U> friend class CMAStopCriteria;
42 template <class U, class V> friend class IPOPCMAStrategy;
43 template <class U, class V> friend class BIPOPCMAStrategy;
44 friend class CovarianceUpdate;
45 friend class ACovarianceUpdate;
46 template <class U> friend class errstats;
47 friend class VDCMAUpdate;
48
49 public:
50 CMAParameters() {} //TODO: var init even if this constructor is not supposed to be used for now.
51
61 CMAParameters(const int &dim,
62 const double *x0,
63 const double &sigma,
64 const int &lambda=-1,
65 const uint64_t &seed=0,
66 const TGenoPheno &gp=TGenoPheno());
67
76 CMAParameters(const std::vector<double> &x0,
77 const double &sigma,
78 const int &lambda=-1,
79 const uint64_t &seed=0,
80 const TGenoPheno &gp=TGenoPheno());
81
91 CMAParameters(const std::vector<double> &x0,
92 const std::vector<double> &sigma,
93 const int &lambda=-1,
94 const std::vector<double> &lbounds=std::vector<double>(),
95 const std::vector<double> &ubounds=std::vector<double>(),
96 const uint64_t &seed=0);
97
99
103 void initialize_parameters();
104
105
106 void reset_as_fixed(const int &k);
107
111 void set_noisy();
112
118 void set_algo(const int &algo)
119 {
120 this->_algo = algo;
121 /*if (this->_tpa != 0
122 && (this->_algo == 6 // sepCMAES
123 || this->_algo == 7 //sepIPOP_CMAES
124 || this->_algo == 8 //sepBIPOP_CMAES
125 || this->_algo == 9 //sepaCMAES
126 || this->_algo == 10 //sepaIPOP_CMAES
127 || this->_algo == 11 //sepaBIPOP_CMAES
128 || this->_algo == 12 //VD_CMAES
129 || this->_algo == 13 //VD_IPOP_CMAES
130 || this->_algo == 14)) //VD_BIPOP_CMAES
131 set_tpa(2); */ // XXX: deactivated until flaw is fixed
132 }
133
138 void set_str_algo(const std::string &algo)
139 {
140 std::map<std::string,int>::const_iterator mit;
142 Parameters<TGenoPheno>::_algo = (*mit).second;
143 else LOG(ERROR) << "unknown algorithm " << algo << std::endl;
144 if (algo.find("sep")!=std::string::npos)
145 set_sep();
146 if (algo.find("vd")!=std::string::npos)
147 set_vd();
148 }
149
154 double get_sigma_init() const
155 {
156 return _sigma_init;
157 }
158
165 void set_gradient(const bool &gradient)
166 {
167 this->_with_gradient = gradient;
168 /*if (this->_tpa != 0)
169 set_tpa(2);*/ // TPA default when gradient is activated.
170 }
171
175 void set_sep();
176
181 bool is_sep() const { return _sep; }
182
186 void set_vd();
187
192 bool is_vd() const { return _vd; }
193
200 void set_fixed_p(const int &index, const double &value);
201
206 void unset_fixed_p(const int &index);
207
212 inline void set_restarts(const int &nrestarts) { _nrestarts = nrestarts; }
213
218 inline int get_restarts() const { return _nrestarts; }
219
224 inline void set_lazy_update(const bool &lz) { _lazy_update = lz; }
225
230 inline bool get_lazy_update() { return _lazy_update; }
231
241 inline void set_elitism(const int &e)
242 {
243 if (e == 0)
244 _elitist = _initial_elitist = _initial_elitist_on_restart;
245 else if (e == 1)
246 {
247 _elitist = true;
248 _initial_elitist = _initial_elitist_on_restart = false;
249 }
250 else if (e == 2)
251 {
252 _initial_elitist = true;
253 _elitist = _initial_elitist_on_restart = false;
254 }
255 else if (e == 3)
256 {
257 _initial_elitist_on_restart = true;
258 _elitist = _initial_elitist = false;
259 }
260 }
261
268 inline void set_stopping_criteria(const int &criteria,
269 const bool &active)
270 {
271 _stoppingcrit.insert(std::pair<int,bool>(criteria,active));
272 }
273
279 void set_tpa(const int &b); // overrides def in parameters.h in order to reset dsigma
280
285 void set_tpa_dsigma(const double &d) { _dsigma = d; }
286
287 private:
288 int _mu;
289 dVec _weights;
290 double _csigma;
291 double _c1;
292 double _cmu;
293 double _cc;
294 double _muw;
295 double _dsigma;
297 // computed once at init for speeding up operations.
298 double _fact_ps;
299 double _fact_pc;
300 double _chi;
302 double _sigma_init;
304 int _nrestarts = 9;
306 double _lazy_value;
308 // active cma.
309 double _cm;
310 double _alphacov;
316 // sep cma (diagonal cov).
317 bool _sep = false;
318 bool _vd = false;
319
320 bool _elitist = false;
321 bool _initial_elitist = false;
322 bool _initial_elitist_on_restart = false;
324 // stopping criteria
325 std::map<int,bool> _stoppingcrit;
326 };
327
328 template<class TGenoPheno>
329 std::map<std::string,int> Parameters<TGenoPheno>::_algos = {{"cmaes",0},{"ipop",1},{"bipop",2},{"acmaes",3},{"aipop",4},{"abipop",5},{"sepcmaes",6},{"sepipop",7},{"sepbipop",8},{"sepacmaes",9},{"sepaipop",10},{"sepabipop",11},{"vdcma",12},{"vdipopcma",13},{"vdbipopcma",14}};
330}
331
332#endif
Active Covariance Matrix update. This implementation closely follows N. Hansen, R....
Definition acovarianceupdate.h:39
Implementation of the BIPOP flavor of CMA-ES, with restarts that control the population of offsprings...
Definition bipopcmastrategy.h:38
Parameters for various flavors of the CMA-ES algorithm.
Definition cmaparameters.h:37
double _deltamaxsigma
Definition cmaparameters.h:312
void set_lazy_update(const bool &lz)
sets the lazy update (i.e. updates the eigenvalues every few steps).
Definition cmaparameters.h:224
double _cmu
Definition cmaparameters.h:292
int _mu
Definition cmaparameters.h:288
void set_restarts(const int &nrestarts)
sets the maximum number of restarts (applies to IPOP and BIPOP).
Definition cmaparameters.h:212
void set_tpa_dsigma(const double &d)
sets dsigma value, use with care.
Definition cmaparameters.h:285
bool is_vd() const
whether algorithm uses vd update.
Definition cmaparameters.h:192
std::map< int, bool > _stoppingcrit
Definition cmaparameters.h:325
void set_stopping_criteria(const int &criteria, const bool &active)
all stopping criteria are active by default, this allows to control them
Definition cmaparameters.h:268
double _cm
Definition cmaparameters.h:309
int get_restarts() const
get the number of restarts (applies to IPOP and BIPOP).
Definition cmaparameters.h:218
double _alphaminusold
Definition cmaparameters.h:311
bool is_sep() const
whether algorithm leverages separability.
Definition cmaparameters.h:181
void set_elitism(const int &e)
sets elitism: 0 -> no elitism 1 -> elitism: reinjects the best-ever seen solution 2 -> initial elitis...
Definition cmaparameters.h:241
double _dsigma
Definition cmaparameters.h:295
double _sigma_init
Definition cmaparameters.h:302
double _alphaminusmin
Definition cmaparameters.h:314
double get_sigma_init() const
returns initial sigma value
Definition cmaparameters.h:154
double _csigma
Definition cmaparameters.h:290
void set_str_algo(const std::string &algo)
sets the optimization algorithm.
Definition cmaparameters.h:138
dVec _weights
Definition cmaparameters.h:289
void set_gradient(const bool &gradient)
activates the gradient injection scheme. If no gradient function is defined, injects a numerical grad...
Definition cmaparameters.h:165
bool get_lazy_update()
get lazy update status.
Definition cmaparameters.h:230
double _chi
Definition cmaparameters.h:300
bool _lazy_update
Definition cmaparameters.h:305
double _c1
Definition cmaparameters.h:291
double _lazy_value
Definition cmaparameters.h:306
double _alphacov
Definition cmaparameters.h:310
void set_algo(const int &algo)
sets the optimization algorithm. Note: overrides Parameters::set_algo
Definition cmaparameters.h:118
double _cc
Definition cmaparameters.h:293
double _muw
Definition cmaparameters.h:294
double _lambdamintarget
Definition cmaparameters.h:313
Holder of the set of evolving solutions from running an instance of CMA-ES.
Definition cmasolutions.h:42
CMA-ES termination criteria, see reference paper in cmastrategy.h.
Definition cmastopcriteria.h:76
This is an implementation of CMA-ES. It uses the reference algorithm and termination criteria of the ...
Definition cmastrategy.h:46
Covariance Matrix update. This is an implementation closely follows: Hansen, N. (2009)....
Definition covarianceupdate.h:38
Main class describing an evolutionary optimization strategy. Every algorithm in libcmaes descends fro...
Definition esostrategy.h:52
an optimizer main class.
Definition esoptimizer.h:72
ESOptimizer()
dummy constructor
Definition esoptimizer.h:77
Implementation of the IPOP flavor of CMA-ES, with restarts that linearly increase the population of o...
Definition ipopcmastrategy.h:36
Generic class for Evolution Strategy parameters.
Definition parameters.h:42
VD-CMA update that is a linear time/space variant of CMA-ES This is an implementation that closely fo...
Definition vdcmaupdate.h:39
Definition errstats.h:34
linear scaling of the parameter space to achieve similar sensitivity across all components.
Definition acovarianceupdate.h:30