2 #include "../Math/LHS.hpp"
3 #include "../Math/RNG.hpp"
4 #include "../Util/Exception.hpp"
9 NOMAD::LHS::LHS(
size_t n,
11 NOMAD::ArrayOfDouble lowerBound,
12 NOMAD::ArrayOfDouble upperBound,
16 _lowerBound(lowerBound),
17 _upperBound(upperBound),
20 if (!_lowerBound.isComplete())
22 std::string s =
"LHS Lower bound needs to be completely defined. Values given: ";
23 s += lowerBound.display();
24 throw NOMAD::Exception(__FILE__, __LINE__, s);
26 if (!_upperBound.isComplete())
28 std::string s =
"LHS Upper bound needs to be completely defined. Values given: ";
29 s += upperBound.display();
30 throw NOMAD::Exception(__FILE__, __LINE__, s);
39 std::vector<NOMAD::Point> NOMAD::LHS::Sample()
const
41 std::vector<NOMAD::Point> samplepoints;
47 std::vector<std::vector<size_t>> Pi;
48 for (
size_t i = 0; i < _n; i++)
50 std::vector<size_t> v = Permutation(_p);
55 for (
size_t j = 0; j < _p; j++)
58 for (
size_t i = 0; i < _n; i++)
61 NOMAD::Double l_i = _lowerBound[i];
62 NOMAD::Double Pi_ij( Pi[i][j] );
63 NOMAD::Double pdouble( _p );
64 NOMAD::Double u_i( _upperBound[i] );
66 NOMAD::Double x_ij = l_i + (Pi_ij - r_ij) / pdouble * (u_i - l_i);
70 samplepoints.push_back(point);
78 std::vector<size_t> NOMAD::LHS::Permutation(
const size_t p)
80 std::vector<size_t> v;
81 for (
size_t j = 1; j <= p; j++)
86 std::random_shuffle(v.begin(), v.end());
static uint32_t rand()
Get a random integer as uint32.
Class for the representation of a point.