2 #include "../../Algos/Mads/MadsIteration.hpp"
3 #include "../../Algos/Mads/LHSearchMethod.hpp"
4 #include "../../Math/LHS.hpp"
5 #include "../../Type/LHSearchType.hpp"
7 void NOMAD::LHSearchMethod::init()
9 _name =
"Latin Hypercube Search Method";
11 auto lhSearch = _runParams->getAttributeValue<NOMAD::LHSearchType>(
"LH_SEARCH");
12 setEnabled(lhSearch.isEnabled());
16 void NOMAD::LHSearchMethod::generateTrialPoints()
20 AddOutputInfo(
"Generate points for " + _name,
true,
false);
21 auto lhSearch = _runParams->getAttributeValue<NOMAD::LHSearchType>(
"LH_SEARCH");
22 const NOMAD::MadsIteration* iteration =
dynamic_cast<const NOMAD::MadsIteration*
>(getParentOfType<NOMAD::MadsIteration*>());
23 auto mesh = iteration->getMesh();
24 auto iterNumber = iteration->getK();
26 size_t n = _pbParams->getAttributeValue<
size_t>(
"DIMENSION");
27 size_t p = (0 == iterNumber) ? lhSearch.getNbInitial() : lhSearch.getNbIteration();
28 auto lowerBound = _pbParams->getAttributeValue<NOMAD::ArrayOfDouble>(
"LOWER_BOUND");
29 auto upperBound = _pbParams->getAttributeValue<NOMAD::ArrayOfDouble>(
"UPPER_BOUND");
30 int seed = _runParams->getAttributeValue<
int>(
"SEED");
31 auto frameCenter = iteration->getFrameCenter();
32 if (
nullptr == frameCenter)
34 throw NOMAD::Exception(__FILE__,__LINE__,
"LHSearchMethod: frame center is NULL");
42 NOMAD::ArrayOfDouble deltaFrameSize = iteration->getMesh()->getDeltaFrameSize();
45 for (
size_t i = 0; i < n; i++)
47 if (!lowerBound[i].isDefined())
49 lowerBound[i] = (*frameCenter)[i] - 10.0 * deltaFrameSize[i] * scaleFactor;
51 if (!upperBound[i].isDefined())
53 upperBound[i] = (*frameCenter)[i] + 10.0 * deltaFrameSize[i] * scaleFactor;
58 NOMAD::LHS lhs(n, p, lowerBound, upperBound, seed);
59 auto pointVector = lhs.Sample();
61 for (
auto point : pointVector)
70 NOMAD::EvalPoint evalPoint(mesh->projectOnMesh(point, *frameCenter));
73 bool inserted = insertTrialPoint(evalPoint);
74 std::string s =
"Generated point";
75 s += (inserted) ?
": " :
" not inserted: ";
76 s += evalPoint.display();
80 AddOutputInfo(
"Generated " + std::to_string(getTrialPointsCount()) +
" points");
81 AddOutputInfo(
"Generate points for " + _name,
false,
true);
const double DEFAULT_EPSILON
Default epsilon used by Double.