libcmaes
A C++11 library for stochastic optimization with CMA-ES
 All Classes Namespaces Functions Variables Typedefs
cmastopcriteria.h
1 
22 #ifndef CMASTOPCRITERIA_H
23 #define CMASTOPCRITERIA_H
24 
25 #include "cmaparameters.h"
26 #include <functional>
27 #include <map>
28 
29 namespace libcmaes
30 {
31 
32  class CMASolutions;
33 
34  template <class TGenoPheno>
35  using StopCriteriaFunc = std::function<int (const CMAParameters<TGenoPheno> &cmap, const CMASolutions &cmas)>;
36 
37  enum CMAStopCritType
38  {
39  CONT = 0,
40  AUTOMAXITER = 7,
41  TOLHISTFUN = 1, // convergence
42  EQUALFUNVALS = 5, // partial success, user error
43  TOLX = 2, // partial success
44  TOLUPSIGMA = -13,
45  STAGNATION = 6, // partial success
46  CONDITIONCOV = -15, // error, user action needed
47  NOEFFECTAXIS = 3, // partial success
48  NOEFFECTCOOR = 4, // partial success
49  MAXFEVALS = 8,
50  MAXITER = 9,
51  FTARGET = 10 // success
52  };
53 
54  template <class TGenoPheno=NoBoundStrategy>
56  {
57  public:
58  StopCriteria(const StopCriteriaFunc<TGenoPheno> &sfunc)
59  :_sfunc(sfunc)
60  {}
61  ~StopCriteria() {}
62 
63  inline bool active() const { return _active; }
64 
65  void set_active(const bool &a) { _active = a; }
66 
67  StopCriteriaFunc<TGenoPheno> _sfunc;
68  bool _active = true;
69  };
70 
74  template <class TGenoPheno=NoBoundStrategy>
76  {
77  friend class CMASolutions;
78 
79  public:
85  ~CMAStopCriteria();
86 
93  int stop(const CMAParameters<TGenoPheno> &cmap, const CMASolutions &cmas) const;
94 
101  int set_criteria_active(const int &c, const bool &active);
102 
103  private:
104  std::map<int,StopCriteria<TGenoPheno> > _scriteria;
105  bool _active;
106  static std::map<int,std::string> _scriterias;
107  };
108 
109  template <class TGenoPheno>
110  std::map<int,std::string> CMAStopCriteria<TGenoPheno>::_scriterias = {{CONT,"OK"},
111  {AUTOMAXITER,"The automatically set maximal number of iterations per run has been reached"},
112  {TOLHISTFUN,"[Success] The optimization has converged"},
113  {EQUALFUNVALS,"[Partial Success] The objective function values are the same over too many iterations, check the formulation of your objective function"},
114  {TOLX,"[Partial Success] All components of covariance matrix are very small (e.g. < 1e-12)"},
115  {TOLUPSIGMA,"[Error] Mismatch between step size increase and decrease of all eigenvalues in covariance matrix. Try to restart the optimization."},
116  {STAGNATION,"[Partial Success] Median of newest values is not smaller than the median of older values"},
117  {CONDITIONCOV,"[Error] The covariance matrix's condition number exceeds 1e14. Check out the formulation of your problem"},
118  {NOEFFECTAXIS,"[Partial Success] Mean remains constant along search axes"},
119  {NOEFFECTCOOR,"[Partial Success] Mean remains constant in coordinates"},
120  {MAXFEVALS,"The maximum number of function evaluations allowed for optimization has been reached"},
121  {MAXITER,"The maximum number of iterations specified for optimization has been reached"},
122  {FTARGET,"[Success] The objective function target value has been reached"}};
123 
124 }
125 
126 #endif
Holder of the set of evolving solutions from running an instance of CMA-ES.
Definition: cmasolutions.h:41
Definition: cmastopcriteria.h:55
CMAStopCriteria()
Constructor: instanciates a predefined set of termination criteria tests, see reference paper in cmas...
Definition: cmastopcriteria.cc:51
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
int stop(const CMAParameters< TGenoPheno > &cmap, const CMASolutions &cmas) const
Termination criteria evaluation: the function iterates and evaluates the predefined criteria...
Definition: cmastopcriteria.cc:244
CMA-ES termination criteria, see reference paper in cmastrategy.h.
Definition: cmastopcriteria.h:75
int set_criteria_active(const int &c, const bool &active)
activates / deactivates a stopping criteria
Definition: cmastopcriteria.cc:267