NOMAD Source  Version 4.0.0 Beta
NMReflective Class Reference

Class to perform the Reflect, Expansion, Inside_Contraction, Outside_Contraction steps of a Nelder Mead algorithm. More...

#include <NMReflective.hpp>

Inheritance diagram for NMReflective:
Collaboration diagram for NMReflective:

Public Member Functions

 NMReflective (const Step *parentStep)
 Constructor. More...
 
virtual ~NMReflective ()
 
void generateTrialPoints () override
 Generate new points to evaluate. More...
 
void setCurrentNMStepType (NMStepType stepType)
 Set the parameters for a given step type. More...
 
NMStepType getNextNMStepType () const
 
- Public Member Functions inherited from Step
 Step ()
 Constructor #1 for MainStep (no parent) More...
 
 Step (const Step *parentStep, const std::shared_ptr< RunParameters > &runParams=nullptr, const std::shared_ptr< PbParameters > &pbParams=nullptr)
 Constructor #2 for child step of a parent sharing the same stopReason. More...
 
 Step (const Step *parentStep, std::shared_ptr< AllStopReasons > stopReasons, const std::shared_ptr< RunParameters > &runParams=nullptr, const std::shared_ptr< PbParameters > &pbParams=nullptr)
 Constructor #3: for a child Step with a provided stopReason (such as an algorithm) More...
 
virtual ~Step ()
 Destructor. More...
 
const StepgetParentStep () const
 Get the parent step. More...
 
virtual const std::string & getName () const
 Get the name of this step. More...
 
void setName (const std::string &name)
 Set the name of this step. More...
 
const std::shared_ptr< AllStopReasons > & getAllStopReasons () const
 
const std::shared_ptr< RunParameters > & getRunParams () const
 
const std::shared_ptr< PbParameters > & getPbParams () const
 
void addCallback (const CallbackType &callbackType, const StepEndCbFunc &stepEndCbFunc)
 Set user callback. More...
 
void addCallback (const CallbackType &callbackType, const HotRestartCbFunc &hotRestartCbFunc)
 
void AddOutputInfo (const std::string &s, bool isBlockStart, bool isBlockEnd) const
 display output More...
 
void AddOutputInfo (const std::string &s, OutputLevel outputLevel=OutputLevel::LEVEL_INFO) const
 
void AddOutputError (const std::string &s) const
 
void AddOutputWarning (const std::string &s) const
 
void AddOutputVeryHigh (const std::string &s) const
 
void AddOutputHigh (const std::string &s) const
 
void AddOutputDebug (const std::string &s) const
 
void AddOutputInfo (OutputInfo outputInfo) const
 
template<typename T >
getParentOfType (const bool stopAtAlgo=true) const
 Template function to get the parent of given type. More...
 
bool isAnAlgorithm () const
 
const AlgorithmgetRootAlgorithm () const
 Get Algorithm ancestor that has no Algorithm ancestor. More...
 
std::string getAlgoName () const
 
virtual std::string getAlgoComment () const
 
virtual void setAlgoComment (const std::string &algoComment, const bool force=false)
 
virtual void resetPreviousAlgoComment (const bool force=false)
 
const std::shared_ptr< MeshBasegetIterationMesh () const
 
const std::shared_ptr< EvalPointgetIterationFrameCenter () const
 
const std::shared_ptr< BarriergetMegaIterationBarrier () const
 
void start ()
 
bool run ()
 
void end ()
 
virtual void hotRestartOnUserInterrupt ()
 Helper for hot restart functionalities. More...
 
void debugShowCallStack () const
 For debugging purposes. Show the stack of Steps for this step. More...
 
- Public Member Functions inherited from NMIterationUtils
 NMIterationUtils (const Step *parentStep)
 Constructor. More...
 
- Public Member Functions inherited from IterationUtils
 IterationUtils (const Step *parentStep)
 Constructor. More...
 
virtual ~IterationUtils ()
 Destructor. More...
 
const SuccessTypegetSuccessType () const
 
void setSuccessType (const SuccessType &success)
 
size_t getTrialPointsCount () const
 
const EvalPointSetgetTrialPoints () const
 
bool insertTrialPoint (const EvalPoint &evalPoint)
 Insert a trial point. More...
 
void clearTrialPoints (void)
 Clear trial points. More...
 
virtual bool postProcessing (const EvalType &evalType)
 Helper for end task. More...
 
void verifyPointsAreOnMesh (const std::string &name) const
 Helper for start task. More...
 
bool snapPointToBoundsAndProjectOnMesh (Point &point, const ArrayOfDouble &lowerBound, const ArrayOfDouble &upperBound)
 Snap a given trial point to the bounds and project on mesh. More...
 
bool evalTrialPoints (Step *step)
 Start evaluation of the trial points. More...
 
size_t getNbEvalPointsThatNeededEval () const
 Get the number of evaluation points in the queue for evaluation. More...
 
void updatePointsWithFrameCenter ()
 Add current frame center as originator of each point in trialPoints. More...
 

Private Member Functions

void init ()
 
virtual void startImp () override
 Implementation of the start task. More...
 
virtual bool runImp () override
 Implementation of the run task. More...
 
virtual void endImp () override
 No end task is required. More...
 
void setNextNMStepType ()
 Helper for NMReflective::runImp. More...
 
void setAfterReflect ()
 
void setAfterExpand ()
 
void setAfterOutsideContract ()
 
void setAfterInsideContract ()
 
bool insertInY (const EvalPoint &x)
 
bool insertInYBest (const EvalPoint &x1, const EvalPoint &x2)
 
bool pointDominatesY0 (const EvalPoint &x) const
 Helper for the setAfterXXXX functions. More...
 
bool YnDominatesPoint (const EvalPoint &x) const
 Helper for the setAfterXXXX functions. More...
 
bool pointDominatesPtsInY (const EvalPoint &x, size_t nb) const
 Helper for the setAfterXXXX functions. More...
 
bool makeListY0 ()
 Create the undominated list of points from Y. More...
 
bool makeListYn ()
 Create the dominated list of points from Y. More...
 
void displayY0nInfo () const
 

Private Attributes

NMStepType _nextStepType
 
Double _delta
 
Double _deltaE
 
Double _deltaOC
 
Double _deltaIC
 
EvalPoint _xr
 
EvalPoint _xe
 
EvalPoint _xoc
 
EvalPoint _xic
 
std::vector< EvalPoint_nmY0
 Vector of undominated points extracted from simplex (the simplex has a loose ordering-->tied points can exist). More...
 
std::vector< EvalPoint_nmYn
 Vector of dominated points extracted from simplex (the simplex has a loose ordering-->tied points can exist). More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Step
static bool getUserTerminate ()
 Interruption call by user. More...
 
static void setUserTerminate ()
 Interruption requested. More...
 
static void userInterrupt (int signalValue)
 Interruption call by user. More...
 
static void debugSegFault (int signalValue)
 
static bool getUserInterrupt ()
 
static void runCallback (CallbackType callbackType, const Step &step, bool &stop)
 Run user callback. More...
 
static void runCallback (CallbackType callbackType, std::vector< std::string > &paramLines)
 
static void disableWarnings ()
 
- Protected Member Functions inherited from Step
void verifyParentNotNull ()
 Helper for constructors. More...
 
void verifyGenerateAllPointsBeforeEval (const std::string &method, const bool expected) const
 Helper for validating steps depending on parameter GENERATE_ALL_POINTS_BEFORE_EVAL. More...
 
void hotRestartBeginHelper ()
 Helpers for hot restart, to be called at the start and end of any override. More...
 
void hotRestartEndHelper ()
 Helpers for hot restart, to be called at the start and end of any override. More...
 
- Protected Member Functions inherited from NMIterationUtils
void updateYCharacteristics (void)
 Update the simplex diameter and volumes from NMIterationUtils::_nmY. More...
 
void displayYInfo (void) const
 Display all the characteristics of a simplex. More...
 
int getRankDZ () const
 
void setStopReason () const
 Set the stop reason according to NMIterationUtils::_currentStepType. More...
 
- Protected Attributes inherited from Step
const Step_parentStep
 The parent of this step. More...
 
std::string _name
 The name of this step. More...
 
std::shared_ptr< AllStopReasons_stopReasons
 The stop reasons of an algorithm. More...
 
std::shared_ptr< RunParameters_runParams
 The run parameters that control a step. More...
 
std::shared_ptr< PbParameters_pbParams
 The problem parameters that control a step. More...
 
- Protected Attributes inherited from NMIterationUtils
Double _rankEps
 The precision for the rank calculation. Default is DEFAULT_EPSILON. More...
 
NMStepType _currentStepType
 The step type (REFLECT, EXPAND, INSIDE_CONTRACTION, OUTSIDE_CONTRACTION) More...
 
std::shared_ptr< NMSimplexEvalPointSet_nmY
 The Nelder Mead simplex. More...
 
- Protected Attributes inherited from IterationUtils
EvalPointSet _trialPoints
 The points generated during the start(). Used for run() and postProcessing(). More...
 
size_t _nbEvalPointsThatNeedEval
 
const Step_parentStep
 
SuccessType _success
 Success type of this step. More...
 
Iteration_iterAncestor
 
MegaIteration_megaIterAncestor
 
- Static Protected Attributes inherited from Step
static bool _userInterrupt
 Interrupt NOMAD if Ctrl-C is pressed. More...
 
static bool _userTerminate
 Terminate NOMAD if Ctrl-C is pressed again. More...
 
static StepEndCbFunc _cbIterationEnd
 
static StepEndCbFunc _cbMegaIterationEnd
 
static HotRestartCbFunc _cbHotRestart
 
static bool _showWarnings
 

Detailed Description

Class to perform the Reflect, Expansion, Inside_Contraction, Outside_Contraction steps of a Nelder Mead algorithm.

The function NMReflective::getNextNMStepType decides which Nelder Mead step comes next. The next step type is updated when calling run (NMReflective::runImp).
The class maintains the lists of undominated (Y0) and dominated points (Yn) extracted from simplex. See the NM-Mads paper: https://link.springer.com/article/10.1007/s10589-018-0016-0 for details.

To compare points we use a dominance operator from EvalPoint::dominates.

Note
The name "reflective" is because all those steps are reflections with different delta.

Definition at line 65 of file NMReflective.hpp.

Constructor & Destructor Documentation

◆ NMReflective()

NMReflective::NMReflective ( const Step parentStep)
inlineexplicit

Constructor.

Parameters
parentStepThe parent of this NM step

Definition at line 84 of file NMReflective.hpp.

85  : Step(parentStep),
86  NMIterationUtils(parentStep)
87  {
88 
89 
90  init();
91  }

◆ ~NMReflective()

virtual NMReflective::~NMReflective ( )
inlinevirtual

Definition at line 92 of file NMReflective.hpp.

92 {}

Member Function Documentation

◆ displayY0nInfo()

void NMReflective::displayY0nInfo ( ) const
private

◆ endImp()

virtual void NMReflective::endImp ( )
inlineoverrideprivatevirtual

No end task is required.

Implements Step.

Definition at line 134 of file NMReflective.hpp.

134 {}

◆ generateTrialPoints()

void NMReflective::generateTrialPoints ( )
overridevirtual

Generate new points to evaluate.

A new point is obtained using the simplex. xt = yc + dela*d. Delta is the reflective factor. The value depends the step type (REFLECT, EXPAND, INSIDE_CONTRACTION, OUTSIDE_CONTRACTION). yc is the barycenter of the simplex. We have d=yc-yn where yn is the last point of Y.
The point is snapped to bounds and projected on the mesh.

Implements IterationUtils.

◆ getNextNMStepType()

NMStepType NMReflective::getNextNMStepType ( ) const
inline

Definition at line 109 of file NMReflective.hpp.

109 { return _nextStepType ; }

◆ init()

void NMReflective::init ( )
private

The delta parameter used to create the trial point is different for EXPANSION, INSIDE_CONTRACTION, OUTSIDE_CONTRACTION. The possible delta parameters are obtained from _runParams. The validity of the parameters are checked.
The flag to perform a standalone Nelder Mead optimization is also set.

◆ insertInY()

bool NMReflective::insertInY ( const EvalPoint x)
private

Insert a point in the simplex Y. If a point is inserted, the last point of Y is removed, return true. If Y is unchanged, the insertion failed, return false.
Update Y0, Yn and the simplex characteristic if necessary.

◆ insertInYBest()

bool NMReflective::insertInYBest ( const EvalPoint x1,
const EvalPoint x2 
)
private

Try to insert the best of two points in the simplex.

Returns
true if the simplex has changed and false otherwise.

◆ makeListY0()

bool NMReflective::makeListY0 ( )
private

Create the undominated list of points from Y.

◆ makeListYn()

bool NMReflective::makeListYn ( )
private

Create the dominated list of points from Y.

◆ pointDominatesPtsInY()

bool NMReflective::pointDominatesPtsInY ( const EvalPoint x,
size_t  nb 
) const
private

Helper for the setAfterXXXX functions.

◆ pointDominatesY0()

bool NMReflective::pointDominatesY0 ( const EvalPoint x) const
private

Helper for the setAfterXXXX functions.

◆ runImp()

virtual bool NMReflective::runImp ( )
overrideprivatevirtual

Implementation of the run task.

Evaluate the trial point and store it locally. Call IterationUtils::postProcessing.

Returns
true if a better point is obtained false otherwise.

Implements Step.

◆ setAfterExpand()

void NMReflective::setAfterExpand ( )
private

EXPAND follows REFLECT. The expand point is xe.
In NM-Mads paper: xr belongs to the expansion zone. xe has been evaluated. The best point between xr and xe is inserted in the simplex Y. If a proper simplex Y is obtained the iteration is completed, if not the next step can be a SHRINK.

◆ setAfterInsideContract()

void NMReflective::setAfterInsideContract ( )
private

INSIDE_CONTRACTION follows REFLECT. The inside contraction point is xic.
In NM-Mads paper: xr belongs to the inside contraction zone. If xic belongs to the inside contraction zone (that is Yn dominates xic), iteration is completed. Otherwise insert xic in Y. If a proper simplex Y is obtained, the iteration is completed, if not the next step can be a SHRINK.

◆ setAfterOutsideContract()

void NMReflective::setAfterOutsideContract ( )
private

OUTSIDE_CONTRACTION follows REFLECT. The outside contraction point is xoc.
In NM-Mads paper: xr belongs to the outside contraction zone. The best point between xr and xoc is inserted in Y. If a proper simplex Y is obtained the iteration is completed, if not the next step can be a SHRINK.

◆ setAfterReflect()

void NMReflective::setAfterReflect ( )
private

Reflect is always the first step of Nelder Mead iteration. The reflect point is xr. In NM-Mads paper, depending on which zone xr belongs to, we perform another step:

  • If xr dominates Y0 -> EXPAND
  • If Yn dominates xr -> INSIDE_CONTRACTION
  • If xr dominates 2 points or more in Y -> iteration completed
  • If xr dominates 0 or 1 point in Y -> OUTSIDE_CONTRACTION

◆ setCurrentNMStepType()

void NMReflective::setCurrentNMStepType ( NMStepType  stepType)

Set the parameters for a given step type.

The name of the step and the value of delta are changed according to stepType.

◆ setNextNMStepType()

void NMReflective::setNextNMStepType ( )
private

Helper for NMReflective::runImp.

◆ startImp()

virtual void NMReflective::startImp ( )
overrideprivatevirtual

Implementation of the start task.

Call NMReflective::generateTrialPoints and update the trial points.

Implements Step.

◆ YnDominatesPoint()

bool NMReflective::YnDominatesPoint ( const EvalPoint x) const
private

Helper for the setAfterXXXX functions.

Member Data Documentation

◆ _delta

Double NMReflective::_delta
private

Definition at line 71 of file NMReflective.hpp.

◆ _deltaE

Double NMReflective::_deltaE
private

Definition at line 71 of file NMReflective.hpp.

◆ _deltaIC

Double NMReflective::_deltaIC
private

Definition at line 71 of file NMReflective.hpp.

◆ _deltaOC

Double NMReflective::_deltaOC
private

Definition at line 71 of file NMReflective.hpp.

◆ _nextStepType

NMStepType NMReflective::_nextStepType
private

Definition at line 70 of file NMReflective.hpp.

◆ _nmY0

std::vector<EvalPoint> NMReflective::_nmY0
private

Vector of undominated points extracted from simplex (the simplex has a loose ordering-->tied points can exist).

Definition at line 75 of file NMReflective.hpp.

◆ _nmYn

std::vector<EvalPoint> NMReflective::_nmYn
private

Vector of dominated points extracted from simplex (the simplex has a loose ordering-->tied points can exist).

Definition at line 76 of file NMReflective.hpp.

◆ _xe

EvalPoint NMReflective::_xe
private

Definition at line 73 of file NMReflective.hpp.

◆ _xic

EvalPoint NMReflective::_xic
private

Definition at line 73 of file NMReflective.hpp.

◆ _xoc

EvalPoint NMReflective::_xoc
private

Definition at line 73 of file NMReflective.hpp.

◆ _xr

EvalPoint NMReflective::_xr
private

Definition at line 73 of file NMReflective.hpp.


The documentation for this class was generated from the following file:
NMReflective::init
void init()
Step::Step
Step()
Constructor #1 for MainStep (no parent)
Definition: Step.hpp:98
NMIterationUtils::NMIterationUtils
NMIterationUtils(const Step *parentStep)
Constructor.
Definition: NMIterationUtils.hpp:126
NMReflective::_nextStepType
NMStepType _nextStepType
Definition: NMReflective.hpp:70