22 #ifndef CMASOLUTIONS_H
23 #define CMASOLUTIONS_H
25 #include "libcmaes_config.h"
26 #include "candidate.h"
27 #include "eo_matrix.h"
28 #include "cmaparameters.h"
29 #include "cmastopcriteria.h"
43 template <
class U,
class V>
friend class CMAStrategy;
44 template <
class U,
class V,
class W>
friend class ESOptimizer;
45 template <
class U,
class V,
class W>
friend class ESOStrategy;
51 template <
class U>
friend class errstats;
54 template <
template <
class X,
class Y>
class U,
class V,
class W>
friend class ACMSurrogateStrategy;
68 template<
class TGenoPheno=GenoPheno<NoBoundStrategy>>
78 std::stable_sort(_candidates.begin(),_candidates.end(),
105 if (_best_candidates_hist.empty())
108 return _initial_candidate;
109 else return Candidate(std::numeric_limits<double>::quiet_NaN(),_xmean);
111 return _best_candidates_hist.back();
120 return _best_seen_candidate;
129 return _worst_seen_candidate;
138 return _candidates.at(r);
143 return _candidates.at(r);
160 return _candidates.size();
181 std::map<int,pli>::const_iterator mit;
182 if ((mit=_pls.find(k))!=_pls.end())
196 return _xmean.size();
266 return _sepcov.data();
294 template<
class TGenoPheno=GenoPheno<NoBoundStrategy>>
298 return cmaparams.
get_gp().pheno(static_cast<dVec>(_cov.diagonal().cwiseSqrt()));
299 else if (cmaparams.
is_sep())
300 return cmaparams.
get_gp().pheno(static_cast<dVec>(_sepcov.cwiseSqrt()));
301 else if (cmaparams.
is_vd())
302 return cmaparams.
get_gp().pheno(static_cast<dVec>((dVec::Constant(cmaparams.
dim(),1.0)+_v.cwiseProduct(_v)).cwiseSqrt().cwiseProduct(_sepcov)));
311 template<
class TGenoPheno=GenoPheno<NoBoundStrategy>>
315 return cmaparams.
get_gp().pheno(static_cast<dVec>(std::sqrt(_sigma)*_cov.diagonal().cwiseSqrt()));
316 else if (cmaparams.
is_sep())
317 return cmaparams.
get_gp().pheno(static_cast<dVec>(std::sqrt(_sigma)*_sepcov.cwiseSqrt()));
318 else if (cmaparams.
is_vd())
319 return cmaparams.
get_gp().pheno(static_cast<dVec>(std::sqrt(_sigma)*(dVec::Constant(cmaparams.
dim(),1.0)+_v.cwiseProduct(_v)).cwiseSqrt().cwiseProduct(_sepcov)));
333 double corr(
const int &i,
const int &j)
const;
386 return _elapsed_time;
395 return _elapsed_last_iter;
440 return _updated_eigen;
458 return _leigenvalues;
467 return _leigenvectors;
475 template <
class TGenoPheno=GenoPheno<NoBoundStrategy>>
476 std::ostream&
print(std::ostream &out,
477 const int &verb_level=0,
478 const TGenoPheno &gp=TGenoPheno())
const;
490 std::vector<Candidate> _candidates;
491 std::vector<Candidate> _best_candidates_hist;
494 double _max_eigenv = 0.0;
495 double _min_eigenv = 0.0;
501 std::vector<Candidate> _k_best_candidates_hist;
502 std::vector<double> _bfvalues;
503 std::vector<double> _median_fvalues;
506 bool _updated_eigen =
true;
510 int _elapsed_time = 0;
511 int _elapsed_last_iter = 0;
513 int _elapsed_eval = 0;
514 int _elapsed_ask = 0;
515 int _elapsed_tell = 0;
516 int _elapsed_stop = 0;
519 std::map<int,pli> _pls;
529 std::vector<RankedCandidate> _candidates_uh;
541 std::ostream& operator<<(std::ostream &out,
const CMASolutions &cmas);
double sigma() const
returns current value of step-size sigma
Definition: cmasolutions.h:339
Implementation of the IPOP flavor of CMA-ES, with restarts that linearly increase the population of o...
Definition: ipopcmastrategy.h:35
Simple surrogate strategy: trains every n steps, and exploits in between, mostly as an example and fo...
Definition: surrogatestrategy.h:215
CMASolutions()
dummy constructor.
Definition: cmasolutions.h:62
bool updated_eigen() const
returns whether the last update is lazy
Definition: cmasolutions.h:438
Holder of the set of evolving solutions from running an instance of CMA-ES.
Definition: cmasolutions.h:41
const dMat & cov_ref() const
returns reference to error covariance matrix
Definition: cmasolutions.h:221
profile likelihood object holder as a set of points and values.
Definition: pli.h:34
Generic class for Evolution Strategy parameters.
Definition: parameters.h:41
const dMat & sepcov_ref() const
returns reference to separable covariance diagonal vector, only applicable to sep-CMA-ES algorithms...
Definition: cmasolutions.h:255
dVec xmean() const
returns current distribution's mean in parameter space
Definition: cmasolutions.h:348
const double * sepcov_data() const
returns pointer to covariance diagnoal vector
Definition: cmasolutions.h:264
std::string status_msg() const
returns current optimization status' message.
Definition: cmasolutions.h:375
unsigned int get_x_size() const
get x vector size
Definition: candidate.h:106
Covariance Matrix update. This is an implementation closely follows: Hansen, N. (2009). Benchmarking a BI-Population CMA-ES on the BBOB-2009 Function Testbed. Workshop Proceedings of the GECCO Genetic and Evolutionary Computation Conference, ACM, pp. 2389-2395.
Definition: covarianceupdate.h:37
std::ostream & print(std::ostream &out, const int &verb_level=0, const TGenoPheno &gp=TGenoPheno()) const
print the solution object out.
Definition: cmasolutions.cc:257
Main class describing an evolutionary optimization strategy. Every algorithm in libcmaes descends fro...
Definition: esostrategy.h:51
int run_status() const
returns current optimization status.
Definition: cmasolutions.h:366
double edm() const
returns expected distance to minimum.
Definition: cmasolutions.h:203
double max_eigenv() const
returns current maximal eigen value
Definition: cmasolutions.h:429
bool get_pli(const int &k, pli &p) const
get profile likelihood if previously computed.
Definition: cmasolutions.h:179
void reset_as_fixed(const int &k)
re-arrange solution object such that parameter 'k' is fixed (i.e. removed).
Definition: cmasolutions.cc:229
void reset()
resets the solution object in order to restart from the current solution with fresh covariance matrix...
Definition: cmasolutions.cc:205
Candidate best_candidate() const
returns current best solution candidate. NOTE: candidates MUST be sorted
Definition: cmasolutions.h:103
void update_eigenv(const dVec &eigenvalues, const dMat &eigenvectors)
updates reference eigenvalue and eigenvectors, for use in termination criteria.
Definition: cmasolutions.cc:196
Definition: errstats.h:33
void sort_candidates()
sorts the current internal set of solution candidates.
Definition: cmasolutions.h:76
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
dMat corr() const
returns correlation matrix
Definition: cmasolutions.cc:138
dMat cov() const
returns error covariance matrix
Definition: cmasolutions.h:212
ACM Surrogate strategy for CMA-ES, follows: 'Surrogate-Assisted Evolutionary Algorithms', Ilya Loshchilov, PhD Thesis, Universite Paris-Sud 11, 2013. http://www.loshchilov.com/phd.html see Chapter 4.
Definition: surrogatestrategy.h:294
dMat sepcsqinv() const
returns inverse root square of separable covariance diagonal matrix, only applicable to sep-CMA-ES al...
Definition: cmasolutions.h:282
dVec stds(const CMAParameters< TGenoPheno > &cmaparams) const
Definition: cmasolutions.h:295
dMat csqinv() const
returns inverse root square of covariance matrix
Definition: cmasolutions.h:273
int nevals() const
returns current budget (number of objective function calls)
Definition: cmasolutions.h:411
int niter() const
returns current number of iterations
Definition: cmasolutions.h:402
Implementation of the BIPOP flavor of CMA-ES, with restarts that control the population of offsprings...
Definition: bipopcmastrategy.h:37
double get_fvalue() const
get function value of this candidate.
Definition: candidate.h:64
const double * cov_data() const
returns pointer to covariance matrix array
Definition: cmasolutions.h:230
void set_xmean(const dVec &xmean)
sets the current distributions' mean in parameter space
Definition: cmasolutions.h:357
Active Covariance Matrix update. This implementation closely follows N. Hansen, R. Ros, "Benchmarking a Weighted Negative Covariance Matrix Update on the BBOB-2010 Noiseless Testbed", GECCO'10, 2010.
Definition: acovarianceupdate.h:38
CMA-ES termination criteria, see reference paper in cmastrategy.h.
Definition: cmastopcriteria.h:75
an optimizer main class.
Definition: esoptimizer.h:71
Candidate get_best_seen_candidate() const
returns the best seen candidate.
Definition: cmasolutions.h:118
std::vector< Candidate > & candidates()
get a reference to the full candidate set
Definition: cmasolutions.h:149
candidate solution point, in function parameter space.
Definition: candidate.h:33
dMat full_cov() const
returns full covariance matrix. Similar to cov() but in case of linear-sized algorithms like sep and ...
Definition: cmasolutions.cc:128
int elapsed_last_iter() const
returns time spent on last iteration
Definition: cmasolutions.h:393
VD-CMA update that is a linear time/space variant of CMA-ES This is an implementation that closely fo...
Definition: vdcmaupdate.h:38
double min_eigenv() const
returns current minimal eigen value
Definition: cmasolutions.h:420
dVec errors(const CMAParameters< TGenoPheno > &cmaparams) const
Definition: cmasolutions.h:312
bool is_sep() const
whether algorithm leverages separability.
Definition: cmaparameters.h:182
dMat sepcov() const
returns separable covariance diagonal matrix, only applicable to sep-CMA-ES algorithms.
Definition: cmasolutions.h:246
This is an implementation of CMA-ES. It uses the reference algorithm and termination criteria of the ...
Definition: cmastrategy.h:45
TGenoPheno get_gp() const
returns the current genotype/phenotype transform object.
Definition: parameters.h:395
void update_best_candidates()
updates the history of best candidates, as well as other meaningful values, typically used in termina...
Definition: cmasolutions.cc:90
bool is_vd() const
whether algorithm uses vd update.
Definition: cmaparameters.h:193
int dim() const
returns the problem's dimension
Definition: parameters.h:341
int fevals() const
returns current number of objective function evaluations
Definition: cmasolutions.h:447
int elapsed_time() const
returns currently elapsed time spent on optimization
Definition: cmasolutions.h:384
dVec eigenvalues() const
returns last computed eigenvalues
Definition: cmasolutions.h:456
int size() const
number of candidate solutions.
Definition: cmasolutions.h:158
Candidate & get_candidate(const int &r)
get a reference to the r-th candidate in current set
Definition: cmasolutions.h:136
int dim() const
return problem dimension.
Definition: cmasolutions.h:194
dMat eigenvectors() const
returns last computed eigenvectors
Definition: cmasolutions.h:465
Candidate get_worst_seen_candidate() const
returns the worst seen candidate.
Definition: cmasolutions.h:127