5 #include "../../Text/TextTools.h" 6 #include "../NumConstants.h" 7 #include "../NumTools.h" 48 if (params.
size() != 1)
49 throw Exception(
"GoldenSectionSearch::init(). This optimizer only deals with one parameter.");
103 throw Exception(
"GoldenSectionSearch::step. Initial interval not set: call the 'setInitialInterval' method first!");
110 NumTools::shift<double>(
x0,
x1,
x2);
121 NumTools::shift<double>(
x3,
x2,
x1);
136 throw NullPointerException(
"GoldenSectionSearch::getFunctionValue. No function associated to this optimizer.");
void doInit(const ParameterList ¶ms) override
This function is called by the init() method and contains all calculations.
bool isToleranceReached() const
Tell if the we reached the desired tolerance with a given new set of estimates.
double getTolerance() const
Get the tolerance parameter.
std::shared_ptr< OptimizationStopCondition > getStopCondition() override
Get the stop condition of the optimization algorithm.
double doStep() override
This function is called by the step() method and contains all calculations.
void setDefaultStopCondition_(std::shared_ptr< OptimizationStopCondition > osc)
const ParameterList & getParameters() const override
static double GOLDEN_RATIO_C()
double getCurrentTolerance() const
Get the current tolerance.
The parameter list object.
bool tolIsReached_
Tell if the tolerance level has been reached.
virtual void setValue(double value)
Set the value of this parameter.
unsigned int getVerbose() const override
Get the verbose level.
const OptimizerInterface * optimizer_
GoldenSectionSearch(std::shared_ptr< FunctionInterface > function)
Golden Section Search optimization algorithm for one parameter.
Parameter & getParameter_(size_t i)
double getFunctionValue() const override
Initialize optimizer.
The base class exception for NULL pointer error. This exception may be thrown when an unexpected NULL...
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
unsigned int nbEvalMax_
The maximum number of function evaluations allowed.
double callCount_
Count the number of times the isToleranceReached() function has been called.
unsigned int nbEval_
The current number of function evaluations achieved.
Partial implementation of the Optimizer interface.
double currentValue_
The current value of the function.
const FunctionInterface & function() const override
Get the current function being optimized.
bool isInitialIntervalSet_
std::string toString(T t)
General template method to convert to a string.
void setInitialInterval(double inf, double sup)
Set intial search interval.
bool hasFunction() const override
Tell if a funciton is associatied to this optimizer.
std::shared_ptr< const FunctionInterface > getFunction() const override
Get the current function being optimized.
std::shared_ptr< OptimizationStopCondition > getDefaultStopCondition() override
Get the default stop condition of the optimization algorithm.
void printMessage(const std::string &message)
Give a message to print to the message handler.
void setStopCondition(std::shared_ptr< OptimizationStopCondition > stopCondition) override
Set the stop condition of the optimization algorithm.
static double GOLDEN_RATIO_R()