Skip to content

Commit f07fa75

Browse files
authored
Merge pull request #45 from IOHprofiler/1+1
Better floating point precision
2 parents 705a13c + 6c36480 commit f07fa75

35 files changed

+1169
-427
lines changed

include/bounds.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace bounds
2222
{
2323
virtual ~BoundCorrection() = default;
2424
Vector lb, ub, db;
25-
double diameter;
25+
Float diameter;
2626
size_t n_out_of_bounds = 0;
2727

2828
BoundCorrection(const Vector &lb, const Vector &ub) : lb(lb), ub(ub), db(ub - lb),
@@ -61,7 +61,7 @@ namespace bounds
6161
{
6262
sampling::Gaussian sampler;
6363

64-
COTN(Eigen::Ref<const Vector> lb, Eigen::Ref<const Vector> ub) : BoundCorrection(lb, ub), sampler(static_cast<size_t>(lb.size()), rng::normal<double>(0, 1.0 / 3.)) {}
64+
COTN(Eigen::Ref<const Vector> lb, Eigen::Ref<const Vector> ub) : BoundCorrection(lb, ub), sampler(static_cast<size_t>(lb.size()), rng::normal<Float>(0, 1.0 / 3.)) {}
6565

6666
Vector correct_x(const Vector &xi, const Mask &oob) override;
6767
};

include/common.hpp

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,45 +22,49 @@
2222
#include <Eigen/Eigenvalues>
2323
#include <Eigen/QR>
2424

25-
using Matrix = Eigen::MatrixXd;
26-
using Vector = Eigen::VectorXd;
27-
using Array = Eigen::ArrayXd;
25+
using Float = long double;
26+
using Matrix = Eigen::Matrix<Float, -1, -1>;
27+
using Vector = Eigen::Matrix<Float, -1, 1>;
28+
using Array = Eigen::Array<Float, -1, 1>;
2829
using size_to = std::optional<size_t>;
2930

3031
template <typename T>
3132
std::ostream &operator<<(std::ostream &os, const std::vector<T> &x);
3233

33-
using FunctionType = std::function<double(const Vector &)>;
34+
using FunctionType = std::function<Float(const Vector &)>;
3435

3536
namespace constants
3637
{
37-
extern double tolup_sigma;
38-
extern double tol_condition_cov;
39-
extern double tol_min_sigma;
40-
extern double stagnation_quantile;
41-
extern double sigma_threshold;
38+
extern Float tolup_sigma;
39+
extern Float tol_condition_cov;
40+
extern Float tol_min_sigma;
41+
extern Float stagnation_quantile;
42+
extern Float sigma_threshold;
4243
extern size_t cache_max_doubles;
4344
extern size_t cache_min_samples;
4445
extern bool cache_samples;
46+
extern Float lb_sigma;
47+
extern Float ub_sigma;
48+
extern bool clip_sigma;
4549
}
4650

4751
/**
4852
* @brief Cdf of a standard normal distribution.
4953
*
5054
* see: ndtr_ndtri.cpp
5155
* @param x lower tail of the probabilty
52-
* @return double quantile corresponding to the lower tail probability q
56+
* @return Float quantile corresponding to the lower tail probability q
5357
*/
54-
double cdf(const double x);
58+
Float cdf(const Float x);
5559

5660
/**
5761
* @brief Percent point function (inverse of cdf) of a standard normal distribution.
5862
*
5963
* see: ndtri.cpp
6064
* @param x lower tail of the probabilty
61-
* @return double quantile corresponding to the lower tail probability q
65+
* @return Float quantile corresponding to the lower tail probability q
6266
*/
63-
double ppf(const double x);
67+
Float ppf(const Float x);
6468

6569
/**
6670
* @brief Generate a sobol sequence using 8 byte integer numbers.
@@ -70,24 +74,24 @@ double ppf(const double x);
7074
* @param seed The current seed of the sobol sequence
7175
* @param quasi the vector of random numbers in which to place the output
7276
*/
73-
void i8_sobol(int dim_num, long long int *seed, double quasi[]);
77+
void i8_sobol(int dim_num, long long int *seed, Float quasi[]);
7478

7579
struct Solution
7680
{
7781
//! Coordinates
7882
Vector x;
7983
//! Function value
80-
double y;
84+
Float y;
8185
//! Generation
8286
size_t t;
8387
//! Evaluations
8488
size_t e;
8589

86-
Solution(const Vector &x, const double y, const size_t t = 0, const size_t e = 0) : x(x), y(y), t(t), e(e)
90+
Solution(const Vector &x, const Float y, const size_t t = 0, const size_t e = 0) : x(x), y(y), t(t), e(e)
8791
{
8892
}
8993

90-
Solution() : Solution({}, std::numeric_limits<double>::infinity()) {}
94+
Solution() : Solution({}, std::numeric_limits<Float>::infinity()) {}
9195

9296
[[nodiscard]] size_t n() const
9397
{
@@ -171,9 +175,9 @@ namespace utils
171175
*
172176
* @param running_times the vector of measured running times
173177
* @param budget the maximum budget allocated to each run
174-
* @return std::pair<double, size_t> (ERT, number of successfull runs)
178+
* @return std::pair<Float, size_t> (ERT, number of successfull runs)
175179
*/
176-
std::pair<double, size_t> compute_ert(const std::vector<size_t> &running_times, size_t budget);
180+
std::pair<Float, size_t> compute_ert(const std::vector<size_t> &running_times, size_t budget);
177181

178182
/**
179183
* \brief calculate the nearest power of two
@@ -184,7 +188,7 @@ namespace utils
184188
template<typename T>
185189
T nearest_power_of_2(const T value)
186190
{
187-
const double val = static_cast<double>(value);
191+
const Float val = static_cast<Float>(value);
188192
return static_cast<T>(pow(2.0, std::floor(std::log2(val))));
189193
}
190194

@@ -251,14 +255,14 @@ namespace rng
251255
size_t dim;
252256
size_t n_samples;
253257

254-
std::vector<double> cache;
258+
std::vector<Float> cache;
255259
Shuffler shuffler;
256260

257261
CachedShuffleSequence(const size_t d);
258262

259-
void fill(const std::vector<double>& c);
263+
void fill(const std::vector<Float>& c);
260264

261-
void transform(const std::function<double(double)>& f);
265+
void transform(const std::function<Float(Float)>& f);
262266

263267
Vector get_index(const size_t idx);
264268

@@ -269,7 +273,7 @@ namespace rng
269273
* @brief distribution which in combination with mt19997 produces the same
270274
* random numbers for gcc and msvc
271275
*/
272-
template <typename T = double>
276+
template <typename T = Float>
273277
struct uniform
274278
{
275279
/**
@@ -290,7 +294,7 @@ namespace rng
290294
* @brief Box-Muller random normal number generator. Ensures similar numbers generated
291295
* on different operating systems.
292296
*/
293-
template <typename T = double>
297+
template <typename T = Float>
294298
struct normal
295299
{
296300
T mu;
@@ -314,7 +318,7 @@ namespace rng
314318
template <typename G>
315319
T operator()(G &gen)
316320
{
317-
static uniform<double> rng;
321+
static uniform<Float> rng;
318322
static T r1, r2;
319323
static bool generate = true;
320324

@@ -338,6 +342,7 @@ namespace rng
338342

339343
namespace functions
340344
{
341-
double sphere(const Vector &x);
342-
double rastrigin(const Vector &x);
345+
Float sphere(const Vector &x);
346+
Float rastrigin(const Vector &x);
347+
Float ellipse(const Vector& x);
343348
}

include/es.hpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ namespace es
1111
OnePlusOneES(
1212
const size_t d,
1313
const Vector &x0,
14-
const double f0,
15-
const double sigma0,
14+
const Float f0,
15+
const Float sigma0,
1616
const size_t budget,
17-
const double target,
17+
const Float target,
1818
const parameters::Modules &modules)
19-
: d(d), sigma(sigma0), decay(1.0 / std::sqrt(static_cast<double>(d) + 1)),
19+
: d(d), sigma(sigma0), decay(1.0 / std::sqrt(static_cast<Float>(d) + 1)),
2020
x(x0), f(f0), t(1), budget(budget), target(target),
2121
rejection_sampling(modules.bound_correction == parameters::CorrectionMethod::RESAMPLE),
2222
sampler(sampling::get(d, modules, 1)),
@@ -29,13 +29,13 @@ namespace es
2929
void operator()(FunctionType &objective);
3030

3131
size_t d;
32-
double sigma;
33-
double decay;
32+
Float sigma;
33+
Float decay;
3434
Vector x;
35-
double f;
35+
Float f;
3636
size_t t;
3737
size_t budget;
38-
double target;
38+
Float target;
3939
bool rejection_sampling;
4040

4141
std::shared_ptr<sampling::Sampler> sampler;
@@ -48,19 +48,19 @@ namespace es
4848
MuCommaLambdaES(
4949
const size_t d,
5050
const Vector &x0,
51-
const double sigma0,
51+
const Float sigma0,
5252
const size_t budget,
53-
const double target,
53+
const Float target,
5454
const parameters::Modules &modules)
5555
: d(d), lambda(d * 5), mu(std::floor(lambda / 4)),
56-
tau(1.0 / std::sqrt(static_cast<double>(d))), // v1 ->
57-
tau_i(1.0 / pow(static_cast<double>(d), .25)),
56+
tau(1.0 / std::sqrt(static_cast<Float>(d))), // v1 ->
57+
tau_i(1.0 / pow(static_cast<Float>(d), .25)),
5858
mu_inv(1.0 / mu),
5959
m(x0), sigma(sigma0 * Vector::Ones(d)),
60-
f(Vector::Constant(lambda, std::numeric_limits<double>::infinity())),
60+
f(Vector::Constant(lambda, std::numeric_limits<Float>::infinity())),
6161
X(d, lambda), S(d, lambda),
62-
f_min(std::numeric_limits<double>::infinity()),
63-
x_min(Vector::Constant(d, std::numeric_limits<double>::signaling_NaN())),
62+
f_min(std::numeric_limits<Float>::infinity()),
63+
x_min(Vector::Constant(d, std::numeric_limits<Float>::signaling_NaN())),
6464
t(0), e(0), budget(budget), target(target),
6565
sampler(sampling::get(d, modules, lambda)),
6666
sigma_sampler(std::make_shared<sampling::Gaussian>(d)),
@@ -78,22 +78,22 @@ namespace es
7878
size_t d;
7979
size_t lambda;
8080
size_t mu;
81-
double tau;
82-
double tau_i;
83-
double mu_inv;
81+
Float tau;
82+
Float tau_i;
83+
Float mu_inv;
8484

8585
Vector m;
8686
Vector sigma;
8787
Vector f;
8888
Matrix X;
8989
Matrix S;
9090

91-
double f_min;
91+
Float f_min;
9292
Vector x_min;
9393
size_t t;
9494
size_t e;
9595
size_t budget;
96-
double target;
96+
Float target;
9797

9898
std::shared_ptr<sampling::Sampler> sampler;
9999
std::shared_ptr<sampling::Sampler> sigma_sampler;

0 commit comments

Comments
 (0)