libcmaes
A C++11 library for stochastic optimization with CMA-ES
 All Classes Namespaces Functions Variables Typedefs
candidate.h
1 
22 #ifndef CANDIDATE_H
23 #define CANDIDATE_H
24 
25 #include "eo_matrix.h"
26 #include "cmaparameters.h"
27 
28 namespace libcmaes
29 {
33  class Candidate
34  {
35  public:
40  _fvalue(std::numeric_limits<double>::quiet_NaN()) {}
41 
47  Candidate(const double &fvalue,
48  const dVec &x)
49  :_fvalue(fvalue),_x(x)
50  {}
51 
52  ~Candidate() {}
53 
58  inline void set_fvalue(const double &fval) { _fvalue = fval; }
59 
64  inline double get_fvalue() const { return _fvalue; }
65 
70  inline void set_x(const dVec &x) { _x = x; }
71 
76  inline dVec get_x_dvec() const { return _x; }
77 
82  inline dVec& get_x_dvec_ref() { return _x; }
83 
89  inline const double* get_x_ptr() const { return _x.data(); }
90 
95  inline std::vector<double> get_x() const
96  {
97  std::vector<double> x;
98  x.assign(_x.data(),_x.data()+_x.size());
99  return x;
100  }
101 
106  inline unsigned int get_x_size() const { return _x.size(); }
107 
112  template<class TGenoPheno>
114  {
115  dVec gx = p.get_gp().pheno(_x);
116  return gx;
117  }
118 
123  inline void set_id(const int &id) { _id = id; }
124 
129  inline int get_id() const { return _id; }
130 
135  inline void set_rank(const int &r) { _r = r; }
136 
141  inline int get_rank() const { return _r; }
142 
143  protected:
144  double _fvalue;
145  dVec _x;
146  int _id = -1;
147  int _r = -1;
148  };
149 
150  class RankedCandidate : public Candidate
151  {
152  public:
153  RankedCandidate(const double &fvalue_mut,
154  Candidate &c,
155  const int &idx)
156  :Candidate(c.get_fvalue(),dVec()),_idx(idx),_fvalue_mut(fvalue_mut)
157  {}
158  ~RankedCandidate() {}
159 
160  int _idx = -1;
161  double _fvalue_mut;
162  int _r1 = 0;
163  int _r2 = 0;
164  double _delta = 0.0;
165  };
166 
167 }
168 
169 #endif
dVec get_x_dvec() const
get parameter vector of this candidate in Eigen vector format.
Definition: candidate.h:76
unsigned int get_x_size() const
get x vector size
Definition: candidate.h:106
int _id
Definition: candidate.h:146
dVec _x
Definition: candidate.h:145
int get_rank() const
get candidate rank
Definition: candidate.h:141
int _r
Definition: candidate.h:147
dVec get_x_pheno_dvec(const CMAParameters< TGenoPheno > &p) const
get pheno transform of parameter vector of this candidate in Eigen vector format. ...
Definition: candidate.h:113
Candidate(const double &fvalue, const dVec &x)
constructor.
Definition: candidate.h:47
Definition: candidate.h:150
void set_x(const dVec &x)
sets parameter vector of this candidate.
Definition: candidate.h:70
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
void set_rank(const int &r)
set candidate rank
Definition: candidate.h:135
double get_fvalue() const
get function value of this candidate.
Definition: candidate.h:64
std::vector< double > get_x() const
get parameter vector copy for this candidate.
Definition: candidate.h:95
double _fvalue
Definition: candidate.h:144
candidate solution point, in function parameter space.
Definition: candidate.h:33
const double * get_x_ptr() const
get parameter vector pointer of this candidate as array. DO NOT USE from temporary candidate object...
Definition: candidate.h:89
int get_id() const
get candidate id
Definition: candidate.h:129
TGenoPheno get_gp() const
returns the current genotype/phenotype transform object.
Definition: parameters.h:395
void set_fvalue(const double &fval)
set candidate's function value.
Definition: candidate.h:58
dVec & get_x_dvec_ref()
get reference parameter vector of this candidate in Eigen vector format.
Definition: candidate.h:82
Candidate()
empty constructor.
Definition: candidate.h:39
void set_id(const int &id)
set candidate id
Definition: candidate.h:123