NOMAD Source  Version 4.0.0 Beta
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LHSearchMethod.cpp
Go to the documentation of this file.
1 
2 #include "../../Algos/Mads/MadsIteration.hpp"
3 #include "../../Algos/Mads/LHSearchMethod.hpp"
4 #include "../../Math/LHS.hpp"
5 #include "../../Type/LHSearchType.hpp"
6 
7 void NOMAD::LHSearchMethod::init()
8 {
9  _name = "Latin Hypercube Search Method";
10 
11  auto lhSearch = _runParams->getAttributeValue<NOMAD::LHSearchType>("LH_SEARCH");
12  setEnabled(lhSearch.isEnabled());
13 }
14 
15 
16 void NOMAD::LHSearchMethod::generateTrialPoints()
17 {
18 
19 
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();
25 
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)
33  {
34  throw NOMAD::Exception(__FILE__,__LINE__,"LHSearchMethod: frame center is NULL");
35  }
36 
37  // Update undefined values of lower and upper bounds to use values based
38  // on DeltaFrameSize.
39  // Based on the code in NOMAD 3, but slightly different.
40  // If we used INF values instead of these, we get huge values for the
41  // generated points. It is not elegant.
42  NOMAD::ArrayOfDouble deltaFrameSize = iteration->getMesh()->getDeltaFrameSize();
43  NOMAD::Double scaleFactor = sqrt(-log(NOMAD::DEFAULT_EPSILON));
44 
45  for (size_t i = 0; i < n; i++)
46  {
47  if (!lowerBound[i].isDefined())
48  {
49  lowerBound[i] = (*frameCenter)[i] - 10.0 * deltaFrameSize[i] * scaleFactor;
50  }
51  if (!upperBound[i].isDefined())
52  {
53  upperBound[i] = (*frameCenter)[i] + 10.0 * deltaFrameSize[i] * scaleFactor;
54  }
55  }
56 
57  // Apply Latin Hypercube algorithm
58  NOMAD::LHS lhs(n, p, lowerBound, upperBound, seed);
59  auto pointVector = lhs.Sample();
60 
61  for (auto point : pointVector)
62  {
63  // Make an EvalPoint from the Point.
64  // We do not need the Eval part of EvalPoint right now,
65  // but it will be used soon. Could be refactored, but
66  // not high priority. Note that an EvalPointSet compares
67  // the Point part of the EvalPoints only.
68 
69  // Projection without scale
70  NOMAD::EvalPoint evalPoint(mesh->projectOnMesh(point, *frameCenter));
71 
72  // Test if the point could be inserted correctly
73  bool inserted = insertTrialPoint(evalPoint);
74  std::string s = "Generated point";
75  s += (inserted) ? ": " : " not inserted: ";
76  s += evalPoint.display();
77  AddOutputInfo(s);
78  }
79 
80  AddOutputInfo("Generated " + std::to_string(getTrialPointsCount()) + " points");
81  AddOutputInfo("Generate points for " + _name, false, true);
82 
83 }
const double DEFAULT_EPSILON
Default epsilon used by Double.
Definition: defines.hpp:63