libcmaes 0.10.2
A C++11 library for stochastic optimization with CMA-ES
Loading...
Searching...
No Matches
scaling.h
1
27#ifndef LSCALING_H
28#define LSCALING_H
29
30#include <libcmaes/eo_matrix.h>
31#include <limits>
32#include <iostream>
33
34namespace libcmaes
35{
36
38 {
39 friend class CMASolutions;
40 template <class U, class V> friend class GenoPheno;
41
42 public:
44
45 NoScalingStrategy(const double *lbounds,
46 const double *ubounds,
47 const int &dim)
48 {
51 (void)dim;
52 }
53
55
56 void scale_to_internal(dVec &x,
57 const dVec &y) const
58 {
59 x = y;
60 }
61
62 void scale_to_f(const dVec &x,
63 dVec &y) const
64 {
65 y = x;
66 }
67
68 void remove_dimensions(const std::vector<int> &k)
69 {
70 (void)k;
71 }
72
73 bool is_id() const
74 {
75 return _id;
76 }
77
78 private:
79 double _intmin = -std::numeric_limits<double>::max();
80 double _intmax = std::numeric_limits<double>::max();
81 bool _id = true;
82 };
83
85 {
86 friend class CMASolutions;
87 template <class U, class V> friend class GenoPheno;
88
89 public:
90 linScalingStrategy() // identity scaling
91 :_scaling(dVec::Constant(1,1.0)),_shift(dVec::Zero(1)),_id(true)
92 {
93 }
94
95 linScalingStrategy(const double *lbounds,
96 const double *ubounds,
97 const int &dim)
98 :_id(false)
99 {
100 compute_scaling(lbounds,ubounds,dim);
101 }
102
103 linScalingStrategy(const dVec &scaling,
104 const dVec &shift)
105 :_scaling(scaling),_shift(shift),_id(false)
106 {}
107
109
110 void compute_scaling(const double *lbounds,
111 const double *ubounds,
112 const int &dim)
113 {
114 dVec vlbounds = Eigen::Map<dVec>(const_cast<double*>(lbounds),dim);
115 dVec vubounds = Eigen::Map<dVec>(const_cast<double*>(ubounds),dim);
116 dVec denom = vubounds-vlbounds;
117 denom = denom.cwiseMin(std::numeric_limits<double>::max()); // protects against overflow
118 _scaling = (dVec::Constant(dim,_intmax)-dVec::Constant(dim,_intmin)).cwiseQuotient(denom);
119 _shift = dVec::Constant(dim,_intmax) - _scaling.cwiseProduct(vubounds);
120 }
121
122 void scale_to_internal(dVec &x,
123 const dVec &y) const
124 {
125 x = y.cwiseProduct(_scaling) + _shift;
126 }
127
128 void scale_to_f(const dVec &x,
129 dVec &y) const
130 {
131 y = x - _shift;
132 y = y.cwiseQuotient(_scaling);
133 }
134
135 bool is_id() const { return _id; }
136
137 void remove_dimensions(const std::vector<int> &k)
138 {
139 for (const int i: k)
140 {
141 removeElement(_scaling,i);
142 removeElement(_shift,i);
143 }
144 }
145
146 public:
147 double _intmin = 0.0;
148 double _intmax = 10.0;
149 dVec _scaling;
150 dVec _shift;
151
152 public:
153 bool _id = true;
154 };
155
156}
157
158#endif
Holder of the set of evolving solutions from running an instance of CMA-ES.
Definition cmasolutions.h:42
an optimizer main class.
Definition esoptimizer.h:72
Definition genopheno.h:36
Definition scaling.h:38
double _intmin
Definition scaling.h:79
double _intmax
Definition scaling.h:80
Definition scaling.h:85
double _intmax
Definition scaling.h:148
double _intmin
Definition scaling.h:147
linear scaling of the parameter space to achieve similar sensitivity across all components.
Definition acovarianceupdate.h:30